Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL 2.0 sprite draws skewed (transformed) after OpenGL draws

I'm using SDL to create a window and draw OpenGL in it and after drawing OpenGL I use SDL to show sprites (UI). It 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 the window:

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

I create the renderer:

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

I load the texture:

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

That's where I do OpenGL drawing. 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 skewed instead of being drawn in a rectangle.

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

What could be the reason of the sprite being transformed like that ? How can I fix this ? Has anybody had a similar problem ?

like image 768
michal.ciurus Avatar asked Jan 23 '26 07:01

michal.ciurus


1 Answers

It almost looks to me as if the camera transform is rotated slightly around the y-axis and the perspective projection is making it looked skewed.

If the sprite is meant to be draw into the screen-space make sure that you have an orthographic projection enabled before the draw, with the width and height being the size of the physical screen (ie. 480x800).

like image 181
Ryan Routon Avatar answered Jan 25 '26 21:01

Ryan Routon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!