SDL context could not be created

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);
}
Hi, you're not using code tags so I can't tell you at exactly what line, but in your code you have this if statement:

1
2
3
4
if (_window = nullptr) // I think you meant to say '==' instead
{
fatalError("SDL window could not be opened!");
}


So fix that.
I would've never noticed something so small, thank you
But the compiler would notice. Compile with warnings on; use your tools to help you.
Last edited on
Topic archived. No new replies allowed.