Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualproanim

Posted 07 February 2013 - 08:33 PM

It must work, you are probably doing something wrong. For me it works 100%, with this function, I create window, context and setup everything I need to get started.

 

SDL_Window *MainWin;
SDL_GLContext MainContext;

int InitWindow(const char* title, int width, int height, bool vsync, int OGL_Major, 
	int OGL_Minor, int StencilSize, int DepthSize, int AA)
{
	// init SDL subsystems
	if(SDL_Init(SDL_INIT_VIDEO) == -1)
        return 1;

	// setup OpenGL version
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, OGL_Major);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, OGL_Minor);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

	// setup stencil buffer
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, StencilSize);

	// use double buffering
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	// setup depth buffer
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, DepthSize);

	// setup anti aliasing
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, AA);

	// create main window
	MainWin = SDL_CreateWindow(title, 
		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 
		width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

	MainContext = SDL_GL_CreateContext(MainWin); // attach OpenGL context to window

	// init GLEW
	if (glewInit() != GLEW_OK)
	{
		fprintf(stderr, "Failed to initialize GLEW\n");
		return -1;
	}

	SDL_GL_SetSwapInterval((int)vsync); // vsync

	return 0;
}

 

 

Note: I use GLEW to load OpenGL extensions, I am not sure if that also works for linux.


#1proanim

Posted 07 February 2013 - 08:32 PM

It must work, you are probably doing something wrong. For me it works 100%, with this function, I create window, context and setup everything I need to get started.

 


SDL_Window *MainWin;
SDL_GLContext MainContext;
 

int InitWindow(const char* title, int width, int height, bool vsync, int OGL_Major, int OGL_Minor, int StencilSize, int DepthSize, int AA) { // init SDL subsystems if(SDL_Init(SDL_INIT_VIDEO) == -1) return 1; // setup OpenGL version SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, OGL_Major); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, OGL_Minor); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); // setup stencil buffer SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, StencilSize); // use double buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // setup depth buffer SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, DepthSize); // setup anti aliasing SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, AA); // create main window MainWin = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); MainContext = SDL_GL_CreateContext(MainWin); // attach OpenGL context to window // init GLEW if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } SDL_GL_SetSwapInterval((int)vsync); // vsync return 0; }

 

Note: I use GLEW to load OpenGL extensions, I am not sure if that also works for linux.


PARTNERS