SDL 2.0 sprite draws skewed (transformed) after OpenGL draws

I am using SDL to create a window and draw OpenGL in it, and after drawing OpenGL, I use SDL to display sprites (UI). This worked for me on Windows, OSX and NDK, but it doesn't work for me on iOS. This is how I draw the sprite:

I create a window:

int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
gWindow = SDL_CreateWindow("example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 800, flags);

      

Create a renderer:

gRenderer = SDL_CreateRenderer(gWindow, id, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

      

I am loading texture:

SDL_Texture* newTexture = NULL;
SDL_Surface* loadedSurface = SDL_LoadBMP(path.c_str());
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
SDL_FreeSurface(loadedSurface);

      

What I am drawing is OpenGL. I load .3ds models, load textures, use blending, etc.

And then I draw the sprite:

    dstRect.x = 0.0f;
    dstRect.y = 0.0f;
    dstRect.w = 128.0f;
    dstRect.h = 64.0f;

    SDL_RenderCopy(gRenderer, newTexture, NULL , &dstRect);

SDL_RenderPresent(gRenderer);

      

the result is strange. The sprite shows skews instead of drawing in a rectangle.

result http://vvcap.net/db/zHhZwoZa1ng7caeP1BG3.png

What could be the reason that the sprite will be transformed this way? How can I fix this? Has anyone had a similar problem?

+3


source to share


2 answers


I didn't find a solution but SDL_RenderCopy

used instead SDL_RenderCopyEx

SDL_RenderCopyEx

.



0


source


It seems to me that the camera transform rotates slightly around the y-axis, and the perspective of the projection makes it distorted.



If the sprite is designed to draw in screen space, make sure you have an orthographic projection before drawing, with the width and height being the size of the physical screen (i.e. 480x800).

+1


source







All Articles