@@ -28,6 +28,9 @@ int Engine::init(void* handle)
2828 SDL_RaiseWindow (window_);
2929 renderer_ = SDL_CreateRenderer (window_, -1 , SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE /* | SDL_RENDERER_PRESENTVSYNC*/ );
3030
31+ tex_ = SDL_CreateTexture (renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, start_w_, start_h_);
32+ setRenderTarget (tex_);
33+
3134 SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, " 1" );
3235 SDL_EventState (SDL_DROPFILE, SDL_ENABLE);
3336
@@ -112,7 +115,7 @@ BP_Texture* Engine::createYUVTexture(int w, int h)
112115
113116void Engine::updateYUVTexture (BP_Texture* t, uint8_t * data0, int size0, uint8_t * data1, int size1, uint8_t * data2, int size2)
114117{
115- SDL_UpdateYUVTexture (testTexture (t) , nullptr , data0, size0, data1, size1, data2, size2);
118+ SDL_UpdateYUVTexture (t , nullptr , data0, size0, data1, size1, data2, size2);
116119}
117120
118121BP_Texture* Engine::createARGBTexture (int w, int h)
@@ -127,7 +130,7 @@ BP_Texture* Engine::createARGBRenderedTexture(int w, int h)
127130
128131void Engine::updateARGBTexture (BP_Texture* t, uint8_t * buffer, int pitch)
129132{
130- SDL_UpdateTexture (testTexture (t) , nullptr , buffer, pitch);
133+ SDL_UpdateTexture (t , nullptr , buffer, pitch);
131134}
132135
133136void Engine::renderCopy (BP_Texture* t, int x, int y, int w, int h, double angle, int inPresent)
@@ -143,16 +146,42 @@ void Engine::renderCopy(BP_Texture* t, int x, int y, int w, int h, double angle,
143146
144147void Engine::renderCopy (BP_Texture* t /* = nullptr*/ , double angle)
145148{
146- SDL_RenderCopyEx (renderer_, testTexture (t) , nullptr , &rect_, angle, nullptr , SDL_FLIP_NONE);
149+ SDL_RenderCopyEx (renderer_, t , nullptr , &rect_, angle, nullptr , SDL_FLIP_NONE);
147150 render_times_++;
148151}
149152
153+ void Engine::renderPresent ()
154+ {
155+ setRenderTarget (nullptr );
156+ SDL_RenderCopy (renderer_, tex_, nullptr , nullptr );
157+ SDL_RenderPresent (renderer_);
158+ resetRenderTarget ();
159+ }
160+
150161void Engine::renderCopy (BP_Texture* t, BP_Rect* rect0, BP_Rect* rect1, double angle, int inPresent /* = 0*/ )
151162{
152163 SDL_RenderCopyEx (renderer_, t, rect0, rect1, angle, nullptr , SDL_FLIP_NONE);
153164 render_times_++;
154165}
155166
167+ void Engine::getMouseState (int & x, int & y)
168+ {
169+ SDL_GetMouseState (&x, &y);
170+ int w, h;
171+ SDL_GetWindowSize (window_, &w, &h);
172+ x *= 1.0 * start_w_ / w;
173+ y *= 1.0 * start_h_ / h;
174+ }
175+
176+ void Engine::setMouseState (int x, int y)
177+ {
178+ int w, h;
179+ SDL_GetWindowSize (window_, &w, &h);
180+ x /= 1.0 * start_w_ / w;
181+ y /= 1.0 * start_h_ / h;
182+ SDL_WarpMouseInWindow (window_, x, y);
183+ }
184+
156185int Engine::pollEvent (BP_Event& e)
157186{
158187 int r = SDL_PollEvent (&e);
@@ -167,6 +196,14 @@ int Engine::pollEvent(BP_Event& e)
167196 else if (key == BP_CONTROLLER_BUTTON_Y) { key = BP_CONTROLLER_BUTTON_X; }
168197 }
169198 }
199+ if (e.type == BP_MOUSEMOTION || e.type == BP_MOUSEBUTTONDOWN || e.type == BP_MOUSEBUTTONUP)
200+ {
201+ int w, h;
202+ SDL_GetWindowSize (window_, &w, &h);
203+ e.motion .x *= 1.0 * start_w_ / w;
204+ e.motion .y *= 1.0 * start_h_ / h;
205+
206+ }
170207 return r;
171208}
172209
@@ -336,7 +373,7 @@ void Engine::createAssistTexture(int w, int h)
336373 // tex_ = createYUVTexture(w, h);
337374 tex2_ = createARGBRenderedTexture (w, h);
338375 // tex_ = createARGBRenderedTexture(768, 480);
339- setPresentPosition ( );
376+ // SDL_SetTextureBlendMode(tex2_, SDL_BLENDMODE_BLEND );
340377}
341378
342379void Engine::setPresentPosition ()
0 commit comments