SDL not rendering a screen on game window












0














I'm struggling to get a square to render on the game window with SDL. I have a two files, SZ_Player.h, and SZ.Player.cpp, and then the main of course. I have initialized the SZ_Player in the main as well by doing "SZ_Player examplePlayer", as well as including it by doing "include "SZ_Player.h".



I'm not exactly sure why it's not showing up, I have images below of the codes:



SZ_Player.h



#ifndef playerFile
#define playerFile

#include <iostream>
#include "SDL.h"

class SZ_Player
{
public:
SZ_Player();
~SZ_Player();

void Init();
void Update();
void Input();
void Render(SDL_Renderer* pRenderer);
SDL_Rect player;
int x, y, height, width, R, G, B;
};

#endif


SZ_Player.cpp



#include "SZ_Player.h"

SZ_Player::SZ_Player()
{

}
SZ_Player::~SZ_Player()
{

}

void SZ_Player::Init()
{
player.x = 70;
player.y = 70;
player.w = 100;
player.h = 100;

R = 255;
G = 255;
B = 255;
}

void SZ_Player::Update()
{

}

void SZ_Player::Input()
{

}

void SZ_Player::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, R, G, B, 255);
SDL_RenderDrawRect(pRenderer, &player);
}


main.cpp



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
while (!done)
{
aTimer.resetTicksTimer();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}









share|improve this question
























  • Maybe you should print something if the SDL_Init() in main fails.
    – drescherjm
    Nov 20 at 17:34












  • Why is done a global variable?
    – drescherjm
    Nov 20 at 17:35






  • 1




    I always wonder how people even think of posting pictures of their code instead of simply copy paste it.
    – Yastanub
    Nov 20 at 18:16










  • Thank you for the replies, any idea why it's not rendering?
    – Mistyisty
    Nov 20 at 18:42






  • 3




    You still did not copy and paste your code as text. You have to make it easy for people to duplicate your result. No one is going to type all this code in to help you for free. Also parts of the code are hidden by the size of the window.
    – drescherjm
    Nov 20 at 19:01


















0














I'm struggling to get a square to render on the game window with SDL. I have a two files, SZ_Player.h, and SZ.Player.cpp, and then the main of course. I have initialized the SZ_Player in the main as well by doing "SZ_Player examplePlayer", as well as including it by doing "include "SZ_Player.h".



I'm not exactly sure why it's not showing up, I have images below of the codes:



SZ_Player.h



#ifndef playerFile
#define playerFile

#include <iostream>
#include "SDL.h"

class SZ_Player
{
public:
SZ_Player();
~SZ_Player();

void Init();
void Update();
void Input();
void Render(SDL_Renderer* pRenderer);
SDL_Rect player;
int x, y, height, width, R, G, B;
};

#endif


SZ_Player.cpp



#include "SZ_Player.h"

SZ_Player::SZ_Player()
{

}
SZ_Player::~SZ_Player()
{

}

void SZ_Player::Init()
{
player.x = 70;
player.y = 70;
player.w = 100;
player.h = 100;

R = 255;
G = 255;
B = 255;
}

void SZ_Player::Update()
{

}

void SZ_Player::Input()
{

}

void SZ_Player::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, R, G, B, 255);
SDL_RenderDrawRect(pRenderer, &player);
}


main.cpp



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
while (!done)
{
aTimer.resetTicksTimer();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}









share|improve this question
























  • Maybe you should print something if the SDL_Init() in main fails.
    – drescherjm
    Nov 20 at 17:34












  • Why is done a global variable?
    – drescherjm
    Nov 20 at 17:35






  • 1




    I always wonder how people even think of posting pictures of their code instead of simply copy paste it.
    – Yastanub
    Nov 20 at 18:16










  • Thank you for the replies, any idea why it's not rendering?
    – Mistyisty
    Nov 20 at 18:42






  • 3




    You still did not copy and paste your code as text. You have to make it easy for people to duplicate your result. No one is going to type all this code in to help you for free. Also parts of the code are hidden by the size of the window.
    – drescherjm
    Nov 20 at 19:01
















0












0








0







I'm struggling to get a square to render on the game window with SDL. I have a two files, SZ_Player.h, and SZ.Player.cpp, and then the main of course. I have initialized the SZ_Player in the main as well by doing "SZ_Player examplePlayer", as well as including it by doing "include "SZ_Player.h".



I'm not exactly sure why it's not showing up, I have images below of the codes:



SZ_Player.h



#ifndef playerFile
#define playerFile

#include <iostream>
#include "SDL.h"

class SZ_Player
{
public:
SZ_Player();
~SZ_Player();

void Init();
void Update();
void Input();
void Render(SDL_Renderer* pRenderer);
SDL_Rect player;
int x, y, height, width, R, G, B;
};

#endif


SZ_Player.cpp



#include "SZ_Player.h"

SZ_Player::SZ_Player()
{

}
SZ_Player::~SZ_Player()
{

}

void SZ_Player::Init()
{
player.x = 70;
player.y = 70;
player.w = 100;
player.h = 100;

R = 255;
G = 255;
B = 255;
}

void SZ_Player::Update()
{

}

void SZ_Player::Input()
{

}

void SZ_Player::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, R, G, B, 255);
SDL_RenderDrawRect(pRenderer, &player);
}


main.cpp



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
while (!done)
{
aTimer.resetTicksTimer();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}









share|improve this question















I'm struggling to get a square to render on the game window with SDL. I have a two files, SZ_Player.h, and SZ.Player.cpp, and then the main of course. I have initialized the SZ_Player in the main as well by doing "SZ_Player examplePlayer", as well as including it by doing "include "SZ_Player.h".



I'm not exactly sure why it's not showing up, I have images below of the codes:



SZ_Player.h



#ifndef playerFile
#define playerFile

#include <iostream>
#include "SDL.h"

class SZ_Player
{
public:
SZ_Player();
~SZ_Player();

void Init();
void Update();
void Input();
void Render(SDL_Renderer* pRenderer);
SDL_Rect player;
int x, y, height, width, R, G, B;
};

#endif


SZ_Player.cpp



#include "SZ_Player.h"

SZ_Player::SZ_Player()
{

}
SZ_Player::~SZ_Player()
{

}

void SZ_Player::Init()
{
player.x = 70;
player.y = 70;
player.w = 100;
player.h = 100;

R = 255;
G = 255;
B = 255;
}

void SZ_Player::Update()
{

}

void SZ_Player::Input()
{

}

void SZ_Player::Render(SDL_Renderer* pRenderer)
{
SDL_SetRenderDrawColor(pRenderer, R, G, B, 255);
SDL_RenderDrawRect(pRenderer, &player);
}


main.cpp



#include <iostream>

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"

using namespace std;

#include "SZ_timer.h"
SZ_Timer aTimer;
const int DELTA_TIME = 10;
bool done = false;

#include "SZ_Player.h"
SZ_Player examplePlayer;

int main(int argc, char *argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0);

// Creates the game window
SDL_Window* game_window = SDL_CreateWindow("Rise", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

// Creates the game render to draw on the game window.
SDL_Renderer* game_renderer = SDL_CreateRenderer(game_window, 0, 0);

// Game Loop
while (!done)
{
aTimer.resetTicksTimer();

SDL_SetRenderDrawColor(game_renderer, 0, 0, 20, SDL_ALPHA_OPAQUE);
SDL_RenderClear(game_renderer);
examplePlayer.Render(game_renderer);
SDL_RenderPresent(game_renderer);

// If less time has passed than allocated block, wait difference
if (aTimer.getTicks() < DELTA_TIME)
{
SDL_Delay(DELTA_TIME - aTimer.getTicks());
}
}
SDL_Quit();

// Exits program
return 0;
}






c++ visual-c++ sdl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 14:32

























asked Nov 20 at 17:22









Mistyisty

234




234












  • Maybe you should print something if the SDL_Init() in main fails.
    – drescherjm
    Nov 20 at 17:34












  • Why is done a global variable?
    – drescherjm
    Nov 20 at 17:35






  • 1




    I always wonder how people even think of posting pictures of their code instead of simply copy paste it.
    – Yastanub
    Nov 20 at 18:16










  • Thank you for the replies, any idea why it's not rendering?
    – Mistyisty
    Nov 20 at 18:42






  • 3




    You still did not copy and paste your code as text. You have to make it easy for people to duplicate your result. No one is going to type all this code in to help you for free. Also parts of the code are hidden by the size of the window.
    – drescherjm
    Nov 20 at 19:01




















  • Maybe you should print something if the SDL_Init() in main fails.
    – drescherjm
    Nov 20 at 17:34












  • Why is done a global variable?
    – drescherjm
    Nov 20 at 17:35






  • 1




    I always wonder how people even think of posting pictures of their code instead of simply copy paste it.
    – Yastanub
    Nov 20 at 18:16










  • Thank you for the replies, any idea why it's not rendering?
    – Mistyisty
    Nov 20 at 18:42






  • 3




    You still did not copy and paste your code as text. You have to make it easy for people to duplicate your result. No one is going to type all this code in to help you for free. Also parts of the code are hidden by the size of the window.
    – drescherjm
    Nov 20 at 19:01


















Maybe you should print something if the SDL_Init() in main fails.
– drescherjm
Nov 20 at 17:34






Maybe you should print something if the SDL_Init() in main fails.
– drescherjm
Nov 20 at 17:34














Why is done a global variable?
– drescherjm
Nov 20 at 17:35




Why is done a global variable?
– drescherjm
Nov 20 at 17:35




1




1




I always wonder how people even think of posting pictures of their code instead of simply copy paste it.
– Yastanub
Nov 20 at 18:16




I always wonder how people even think of posting pictures of their code instead of simply copy paste it.
– Yastanub
Nov 20 at 18:16












Thank you for the replies, any idea why it's not rendering?
– Mistyisty
Nov 20 at 18:42




Thank you for the replies, any idea why it's not rendering?
– Mistyisty
Nov 20 at 18:42




3




3




You still did not copy and paste your code as text. You have to make it easy for people to duplicate your result. No one is going to type all this code in to help you for free. Also parts of the code are hidden by the size of the window.
– drescherjm
Nov 20 at 19:01






You still did not copy and paste your code as text. You have to make it easy for people to duplicate your result. No one is going to type all this code in to help you for free. Also parts of the code are hidden by the size of the window.
– drescherjm
Nov 20 at 19:01



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398308%2fsdl-not-rendering-a-screen-on-game-window%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398308%2fsdl-not-rendering-a-screen-on-game-window%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland