ChoosePixelFormat DeadLock / SDL_CreateWindow gets stuck

Hi all,

I am having a very annoying problem with my code. I am using SDL 2.00 with openGL on visual studio 2013. The problem starts when I try to create a windows using SDL_CreateWindow. The code compiles just fine but when i run it, the window is all white and won’t accept any input whatsoever and also the mouse cursor appears as “waiting”. So it seems like it gets into an infinite loop somewhere. I narrowed it down. It seems like ChoosePixelFormat gets into dead lock state so the window won’t keep running after it. The thing is, I developed 2 other 2D games with the same build(SDL2.00 OpenGL VS2013) with no problems. I can still run those games and SDL_CreateWindow won’t cause any issues. The code is so simple too. its supposed to draw a triangle in the window.

#include "stdafx.h"

void init()
	glClearColor(0.0, 0.0, 0.0, 1.0);
	gluPerspective(45, 640.0 / 480.0, 1.0, 500.0);


void display()
	glVertex3f(0.0, 2.0, -5.0);
	glVertex3f(-2.0, -2.0, -5.0);
	glVertex3f(2.0, -2.0, -5.0);


int main(int argc, char* argv[]){

	SDL_Window * window;
	window = SDL_CreateWindow("OpenGLTest", 300, 300, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
	while (true){

	return 0;


#pragma once

#include <iostream>
#include <SDL.h>
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>

#define PI 3.14159265

using namespace std;

The whole code is posted. The problem isnt the rest of the code. I removed everything else and left only the part where SDL_CreateWindow is called and the problem keeps happening. Anyone has any idea why this is happening and how i can fix it?



I think the problem is more likely that you aren’t calling SDL_PollEvent anywhere in your main loop.

Also, I don’t think this really belongs in the “OpenGL coding: advanced” section of the forum.