Greetings, I have an annoying problem with my engine, the screen can be rotated on the fly, so I should prepare the sprites to be rotated in 90º and also to be rendered in the correct location.
The problem is that I’m trying for a long time but it seems something is wrong with my logic, see the code below:
void SDL_Render_Sprites() {
MT2D_SDL_Rect renderQuad;
MT2D_SDL_Rect Original;
SDL_Point Center;
void *mPixels;
CheckVideoEvent();
int i = 0;
int angle = 0;
while (i < MainEvents.SpriteBuffer_Count) {
Original.w = MainEvents.SpriteBuffer[i].size.X;
Original.h = MainEvents.SpriteBuffer[i].size.Y;
Original.x = 0;
Original.y = 0;
if (mode.h >= mode.w) {
//90º
Center.x = MainEvents.SpriteBuffer[i].size.X;
Center.y = MainEvents.SpriteBuffer[i].size.Y;
angle = 90;
// renderQuad.x = MainEvents.SpriteBuffer[i].scale.Y /2 + (((240 - MainEvents.SpriteBuffer[i].scale.Y - MainEvents.SpriteBufferY[i]) * mode.w) / 320);
renderQuad.x = /*MainEvents.SpriteBuffer[i].scale.Y +*/ (( 320*(240 - MainEvents.SpriteBuffer[i].size.Y - MainEvents.SpriteBufferY[i])/240 ) * mode.w) / 320;
renderQuad.y = ( (240*MainEvents.SpriteBufferX[i])/ 320 * mode.h) / 240;
// renderQuad.y = MainEvents.SpriteBuffer[i].scale.X /2 +((MainEvents.SpriteBufferX[i] + 0) * mode.h) / 240;
renderQuad.w = (((240 * MainEvents.SpriteBuffer[i].scale.X) / 320) * mode.h ) / 320;
renderQuad.h = ((320 * (MainEvents.SpriteBuffer[i].scale.Y) / 240) * mode.w ) / 240;
MT2D_SDL_RenderCopyEx(MainEvents.Render, (MT2D_SDL_Texture*)MainEvents.SpriteBuffer[i].Data, &Original, &renderQuad, angle,&Center, SDL_FLIP_NONE);
}
else {
renderQuad.x = (MainEvents.SpriteBufferX[i] * mode.w) / 320;
renderQuad.y = (MainEvents.SpriteBufferY[i] * mode.h) / 240;
renderQuad.w = (MainEvents.SpriteBuffer[i].scale.X * (mode.w / (MAX_HOR)) * MAX_HOR /*Force the sprites to be rendered where the ASCII text can render.*/) / 320;
renderQuad.h = (MainEvents.SpriteBuffer[i].scale.Y * (mode.h / (MAX_VER)) * MAX_VER) / 240;
MT2D_SDL_RenderCopyEx(MainEvents.Render, (MT2D_SDL_Texture*)MainEvents.SpriteBuffer[i].Data, &Original, &renderQuad, angle, NULL, SDL_FLIP_NONE);
}
i++;
}
}
when I render in a horizontal screen, the render Works just fine (like in 1280x720),
but when I rotate the screen (going to 720x1280), I need to rotate the texture, and with that Idk how to do the proper coord to render them.
Any tip about how to ajust that?
About the code:
MainEvents.SpriteBuffer[i].size is the size of the texture.
MainEvents.SpriteBufferX[i] and MainEvents.SpriteBufferY[i] is where I want to render the texture (in virtual 320x240 coord)
MainEvents.SpriteBuffer[i].scale is the scale that this image should be rendered in a 320x240 space.
//90º part of the code is where I render the rotated texture…