SDL2 Rendering Textures from Vector

Multi tool use
Multi tool use


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);
}
for(int i = 1;i >= 0;i--)
{
Piece.setRectDetails(ExtraSquareWidth*(4-i),0,68,68);
Piece.setCropDetails(SquareWidth*i,0,SquareWidth,SquareHeight);
BlackPieces.push_back(Piece);
}
}
int main( int argc, char * argv )
{
Sprite curBoard(Game.renderer,backgroundImg,0,0,MAX_WINDOWS_WIDTH,MAX_WINDOWS_HEIGHT);
InitializeGame();
while(!Game.quit && Game.mainEvent->type != SDL_QUIT)
{
Game.Begin();
GameDrawer.Draw(curBoard,Game);
for(std::vector<Sprite>::iterator it = BlackPieces.begin();it != BlackPieces.end();it++)
GameDrawer.Draw( *it,Game);
Game.End();
}
Game.~Init();
curBoard.~Sprite();
return 1;
}



`
It Simply shows the board..But If i try drawing directly without pushing into a vector,it works fine..



--Update



Changing to pointers fixed it.`


void InitializeGame()
{
for(int i = 2;i <= 4;i++)
{
Piece = new Sprite(Game.renderer,ChessImg,0,0,0,0);
Piece->setRectDetails(ExtraSquareWidth*(i-2),0,68,68);
Piece->setCropDetails(SquareWidth*i,0,SquareWidth,SquareHeight);
BlackPieces.push_back(Piece);
}
for(int i = 1;i >= 0;i--)
{
Piece = new Sprite(Game.renderer,ChessImg,0,0,0,0);
Piece->setRectDetails(ExtraSquareWidth*(4-i),0,68,68);
Piece->setCropDetails(SquareWidth*i,0,SquareWidth,SquareHeight);
BlackPieces.push_back(Piece);
}
}



`





where is the SDL_RenderPresent?
– Aram
Jul 1 at 23:20





Init.cpp Contains SDL_RenderPresent,SDL_RenderClear,SDL_PollEvent
– Mohanad Ayman
Jul 1 at 23:46





Then add them (at least in a clonable git gist or something) you need to post a MVCE stackoverflow.com/help/mcve OR reduce your code until it only reproduces the bug you're seeing
– Aram
Jul 1 at 23:49






The Problem is that i cant determine the reason of the bug,It's mainly not a Renderer or Texture,Because i made 2 different Sprites and rendered them without any problem..but not when it's a vector Of sprites.
– Mohanad Ayman
Jul 2 at 0:13





After Adding the Sprite to vector,I checked The Sprite dimension in the vector and it was perfectly fine..so the sprites are pushed into vector without a problem but doesn't get rendered
– Mohanad Ayman
Jul 2 at 0:14









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

3J,9Kyj,mrgz9ZBCiVIR yRKkhuTkk,IMRGVqsOif4LjCK,15BXycsMX,A4
0TKcLuUMbirQ

Popular posts from this blog

Rothschild family

Cinema of Italy