Dec 30, 2017 at 7:32pm UTC
I'm trying to make an SDL window, and from what I'm getting everything is running fine for the most part up until I try creating SDL context for the window.
-
#include "Maingame.h"
void fatalError(std::string errorString)
{
std::cout << errorString << std::endl;
std::cout << "Enter any key to quit...";
int tmp;
std::cin >> tmp;
SDL_Quit();
exit(1);
}
Maingame::Maingame()
{
_window = nullptr;
_screenHeight = 1024;
_screenWidth = 768;
_gameState = GameState::PLAY;
}
Maingame::~Maingame()
{
}
void Maingame::gameLoop()
{
while (_gameState != GameState::EXIT)
{
processInput();
drawGame();
}
}
void Maingame::processInput()
{
SDL_Event evnt;
while (SDL_PollEvent(&evnt))
{
switch (evnt.type)
{
case SDL_QUIT:
_gameState = GameState::EXIT;
break;
case SDL_MOUSEMOTION:
std::cout << evnt.motion.x << " " << evnt.motion.y << std::endl;
break;
}
}
}
void Maingame::drawGame()
{
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(_window);
}
void Maingame::run()
{
initSystems();
gameLoop();
}
void Maingame::initSystems()
{
SDL_Init(SDL_INIT_EVERYTHING);
_window = SDL_CreateWindow("Graphics Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _screenWidth, _screenHeight, SDL_WINDOW_OPENGL);
if (_window = nullptr)
{
fatalError("SDL window could not be opened!");
}
SDL_GLContext glContext = SDL_GL_CreateContext(_window);
if (glContext == nullptr)
{
fatalError("SDL_GLContext could not be created!");
}
GLenum error = glewInit();
if (error != GLEW_OK)
{
fatalError("Could not initialize glew!");
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
Dec 30, 2017 at 11:25pm UTC
I would've never noticed something so small, thank you
Dec 31, 2017 at 12:50am UTC
But the compiler would notice. Compile with warnings on; use your tools to help you.
Last edited on Dec 31, 2017 at 12:51am UTC