Posts

Showing posts with the label sdl-2

SDL2 Rendering Textures from Vector

SDL2 Rendering Textures from Vector I'm Trying to store the textures into a vector then draw them on screen from the vector.But it wouldn't draw anything at all,just the board empty.. main.cpp: ` #include <SDL.h> #include <SDL_image.h> #include <SDL_mixer.h> #include <iostream> #include "Sprite.h" #include "Init.h" #include "Drawer.h" #include <vector> int32_t mouseX,mouseY; char* backgroundImg = "download.png"; char* ChessImg = "ChessSprite.png"; int SquareWidth = 64; int SquareHeight= 64; int ExtraSquareWidth = 66; int ExtraSquareHeight = 66; std::vector<Sprite> BlackPieces; Drawer GameDrawer; Init Game; void InitializeGame() { Sprite Piece(Game.renderer,ChessImg,0,0,0,0); for(int i = 2;i <= 4;i++) { Piece.setRectDetails(ExtraSquareWidth*(i-2),0,68,68); Piece.setCropDetails(SquareWidth*i,0,SquareWidth,SquareHeight); BlackPieces.push_back(Piece); } ...

SDL memory leak

SDL memory leak So I tryed to make something on SDL, but on first programm I have memory lear (idk leak or not) so there is some code: #include <stdio.h> #include <SDL.h> #include <SDL_image.h> #include <SDL_ttf.h> #define SCREENSIZEX 180 #define SCREENSIZEY 300 SDL_Window* mainwind = NULL; SDL_Renderer* rend = NULL; TTF_Font* Usefont = NULL; int main(int argc, char* argv) { SDL_Init(SDL_INIT_EVERYTHING); Uint32 windowflags; windowflags = SDL_WINDOW_SHOWN; mainwind = SDL_CreateWindow("FooBar", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREENSIZEX, SCREENSIZEY, windowflags); rend = SDL_CreateRenderer(mainwind, -1, SDL_RENDERER_ACCELERATED); SDL_SetRenderDrawColor(rend, 255, 255, 255, 255); int imgFlags = IMG_INIT_PNG; IMG_Init(imgFlags); TTF_Init(); U...

SDL layered rendering system

SDL layered rendering system I would like help with building a layered rendering system in SDL2. I have a first layer containing a map of Paris with its roads. I need to draw a line between two points on this map - the problem occurs when the before state of this line does not disappear. I need to draw this line over the map and keep this. How do I make s a system to save the map state whithout any overlaid lines drawn, and such that frame by frame I can show the map with the new state of the line overlaid on top of this? Buffering. Render each layer to its own buffer then blit the buffers to the final render surface preserving transparency and perhaps using an alternative blending mode. You may take advantage of optimizations for 2D scrolling if present in the available hardware (I'm not familiar with the SDL API for that, though). – Dai Jul 1 at 8:01 ...