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);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, 640.0 / 480.0, 1.0, 500.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_TRIANGLES);
	glVertex3f(0.0, 2.0, -5.0);
	glVertex3f(-2.0, -2.0, -5.0);
	glVertex3f(2.0, -2.0, -5.0);
	glEnd();

}


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

	
	SDL_Init(SDL_INIT_EVERYTHING); 
	SDL_Window * window;
	window = SDL_CreateWindow("OpenGLTest", 300, 300, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
	init();
	
	
	while (true){
		display();
		SDL_GL_SwapWindow(window);
	}


	
	
	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?

Thanks!

-Omer

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.