New answers tagged

1

Upon first glance, it looks like you call TTF_OpenFont to create your font in your label constructor, but you do not call TTF_CloseFont in the destructor. You should. You also call createSurface in both the constructor and setText. When called from setText, createSurface will immediately allocate a new m_surface and m_texture, causing you to lose the things ...


0

OK so I have a partial answer (more of a kludge) that might eventually lead to the real, proper solution for this. I've added some code to check for a SDL_WINDOWEVENT_RESTORED event; when this occurs, openGL is reinitialised, and all of the textures that were loaded on program start are cleared and re-loaded. This feels very hacky, and carries about a 40MB ...


0

The problem is in a way you use SDL_LockTexture(). You use it completely wrongly, you somehow assume you can pass a surface buffer there, which is not the case. Instead, this function fills the passed pointer to point to its own internal buffer, and as the result, the surface's pointer is being messed up in your code. As was already pointed, you could use ...


1

For no apparent reason, you are filling your loaded image with a solid white color using SDL_FillRect. Also, you seem to clear the renderer without rerendering the texture. You need to SDL_RenderCopy the texture again after clearing the renderer.


0

If you can draw triangles, then you can technically create a 3d engine with it. However, this involves the same amount of math as you need to do OpenGL if not more. First, you need to define positions in 3 dimensional space. This is done by using 3d vectors. To render a triangle, you need 3 vectors, one for each vertex of the triangle. Now, to project a ...


0

As you haven't supplied the particular bitmap you are having trouble with, I cannot guess what is wrong with the bitmap. Your rendering code seems fine on that part. When it comes to the program hanging, the cause is quite clear. When an SDL_QUIT event is received, you quit your loop that is waiting for that particular event, and call SDL_Quit();. However, ...


3

You need to implement some sort of a timer. A basic implementation could work like the following: start by calculating the next time when a block should move, which might look something like nextMoveTime = SDL_GetTicks() + 200;. Then, each frame/update cycle, you would check if enough time has passed and if so, move the block. So something simple like if (...


-3

You need a keyboard with n-key rollover


2

You are loading part.png and creating the surface for each tail part in a loop. That's incredibly slow. Instead you should load it once, at the program initialization and just use it in drawing. You should get rid of these in drawPart(): auto surface = IMG_Load("part.png"); texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_FreeSurface(surface);



Top 50 recent answers are included