michal.ciurus
michal.ciurus

Reputation: 3664

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 ?

Upvotes: 3

Views: 684

Answers (2)

michal.ciurus
michal.ciurus

Reputation: 3664

I didn't find a solution but I just used SDL_RenderCopyEx instead of SDL_RenderCopy and it worked.

Upvotes: 0

Ryan Routon
Ryan Routon

Reputation: 86

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).

Upvotes: 1

Related Questions