SDL not rendering a screen on game window
up vote
0
down vote
favorite
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
|
show 3 more comments
up vote
0
down vote
favorite
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
Maybe you should print something if the SDL_Init() in main fails.
– drescherjm
Nov 20 at 17:34
Why isdone
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
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
c++ visual-c++ sdl
edited Nov 21 at 14:32
asked Nov 20 at 17:22
Mistyisty
204
204
Maybe you should print something if the SDL_Init() in main fails.
– drescherjm
Nov 20 at 17:34
Why isdone
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
|
show 3 more comments
Maybe you should print something if the SDL_Init() in main fails.
– drescherjm
Nov 20 at 17:34
Why isdone
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
|
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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