working with OGL 3.x

hi

i want to start working with OpenGL 3.x, and i have some questions?

  1. how can i detcet the version of OGL driver before creating context?

  2. how can i create OpenGL3.x context? ( in WIN32 and linux)


...
wglMakeCurrent(hDC,hRC); // from your existing code

// from now on, it's GL3.x initialization	

	PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
	if(!wglCreateContextAttribsARB){
		MessageBoxA(0,"OpenGL3.0 not supported or enabled in NVemulate",0,0);
	}else{
		int attribs[] = {
			WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
			WGL_CONTEXT_MINOR_VERSION_ARB, 0,
			WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 
			0
		};
		
		HGLRC gl3Ctx = wglCreateContextAttribsARB(hDC, 0, attribs);
		if(gl3Ctx){
			wglDeleteContext(hRC);
			hRC =gl3Ctx;
			wglMakeCurrent(hDC,hRC);
			//prints("opengl3 success");
			//prints((char*)glGetString(GL_VERSION));
		}else{
			MessageBoxA(0,"OpenGL3.0 context did not init, staying in 2.1",0,0);
		}
	}

  1. to get the driver version try:

printf ("Version: %s
", glGetString (GL_VERSION));

  1. In linux to create an OpenGL3.x context, I use freeglut:

 glutInit( &argc, argv );
 glutInitContextVersion( 3, 0 );

This should be valid in windows also since freeglut is cross-platform but I am not a windows user so haven’t tested it there.

You will have to use the Testing Release: Freeglut 2.6.0 Release Candidate 1 rather than the standard vanilla version. If you want to see more of how they actually do that under the hood, you could probably look at their code since it is open.

For beginning OpenGL, definitely use freeglut as mentioned.

Thought if you’d rather glX/wgl, I can post you a short Xlib/glX code to create a GL window and GL3.x context in Linux.

Just let us know.

For beginning OpenGL, definitely use freeglut as mentioned.

Thought if you’d rather glX/wgl, I can post you a short Xlib/glX code to create a GL window and GL3.x context in Linux.

Just let us know. [/QUOTE]

thanks, but i am not beginner in OpenGL. just i dont know features and changes of OGL 3.x and how to work with it.

http://www.flashbang.se - for a few tutorials on how to switch to 3.x

for the rest you can read whats new in this forum section, it’s not really that much new stuff, mainly it’s a lot of ext stuff that went core like fbo texture arrays, geometry shaders, instancing, VAO, and so on.
The most important thing is what got removed.
As usual it’s all in the registry.

good tutorial , thanks

how can i get opengl version before creating context and window?
( glGetString(GL_VERSION) dose not work before creating context)

(i need to get minor version for put it in the:
WGL_CONTEXT_MINOR_VERSION_ARB)

You can’t. You need to create temporary window and context, if you need something like that.

And be aware that although spec states that the previous implementations of OpenGL (<3.2) ignore WGL_CONTEXT_PROFILE_MASK_ARB attribute, I have realized that it is not (always) true and have a problem to create GL 3.0 context with WGL_CONTEXT_PROFILE_MASK_ARB attribute included into attribute list.

Just a followup on a previous post – The Freeglut 2.6.0 Release Candidate 1 has a sample (/freeglut-2.6.0/progs/demos/smooth_opengl3/smooth_opengl3.c) showing how to use a single function call glutInitContextVersion (3, 1) to get an opengl 3.1 context and demos a simple shader. This still may be helpful for those who are used to working with glut and want to try and work with the new ogl3 functionality without focusing too much on the wgl\glx boilerplate details.

Thank you! It is a very useful link for those who start OpenGL programming and do not want to bother with windows management.

But the freeglut cannot solve problems built in drivers, because it is only a wrapper around GL and windows interface APIs. The previous post was just a warning about what might happen if try to use new attributes on the old (3.0) contexts.

how can i do MRT in GLSL 150 an OpenGL 3.x?

[fragment shader]
#version 150

out vec4 out_Color0;
out vec4 out_Color1;

void main()
{
out_Color0 = vec4(0.0, 0.0, 0.0, 0.0);
out_Color1 = vec4(0.0, 0.0, 0.0, 0.0);
}

[C++ code]
// Create and bind shader
glBindFragDataLocation(programID, 0, “out_Color0”);
glBindFragDataLocation(programID, 1, “out_Color1”);

// Drawing code
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
GLuint buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
glDrawBuffers(2, buffers);

// draw stuff