Am i doing this right? (OpenGL 3.0+ context)

Started by
4 comments, last by Brother Bob 10 years, 11 months ago

Hi, i've been trying to add some code to my engine to create an opengl 3.1 context, to keep up to date with current technology. However, it's dosen't seem to do anything different... I though depreciated features where phased out in 3.1, and that you absolutely needed shaders to render anything, but all my old code still work and i can even render stuff without shaders. Is there a way to be sure the context i am creating is what i am trying to do?

For example, i added this pieces of code in my engine initialization procedure:


    if(!SetupPixelFormatDescriptor(hDC)){
	PostQuitMessage(0);
	return false;
    }

    #ifndef COMPILE_FOR_OPENGL_3_1_
        hRC = wglCreateContext(hDC);
        wglMakeCurrent(hDC, hRC);
    #else
        GLenum err = glewInit();
        HGLRC tempContext = wglCreateContext(hDC);
        wglMakeCurrent(hDC, tempContext);

	int attribs[] =
	{
        WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
        WGL_CONTEXT_MINOR_VERSION_ARB, 1,
        WGL_CONTEXT_FLAGS_ARB, 0,
        0};

	PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
	
        hRC = CreateContextAttribsARB(hDC, 0, attribs);
	wglMakeCurrent(NULL,NULL);
	wglDeleteContext(tempContext);
	wglMakeCurrent(hDC, hRC);
    #endif

But for the reasons listed above, it dosen't seem to do much... I followed the new red book instruction (OpenGL Programming guide 7th edition).

Am i doing this right?

Advertisement

The WGL_CONTEXT_FLAG_ARG option needs the WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB flag to produce a forward-compatible rendering context. Without the flag, you get a backward compatible context with all the old functions as well as the new ones.

So, i would have to do

WGL_CONTEXT_FLAG_ARG | WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB

?

What's the point of using WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB if all it does is remove depreciated stuff?

And how something can be "foward compatible"?!? I mean, backward compatible make sense, but foward compatible sound like

"this is compatible with things that don't exist yet"!

i know what they mean, but it's weird...

So, i would have do

WGL_CONTEXT_FLAG_ARG | WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB

?

The bit goes into the value, not the option.

WGL_CONTEXT_FLAG_ARG, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB

What's the point of using WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB if all it does is remove depreciated stuff?

You asked how to get rid of the deprecated stuff, and that bit gets rid of the deprecated stuff. So the point of it should be obvious to you :)

Ahh, i think i just got how the attriblist array work... so, aren't i am missing a 0 at the end of my example above?

For example, this code terminate it with 2 zeros. I mean, mine too... but isin't the parameters working in pair? Mine have an uneven number of elements, does it matter?

I can't find any good documentation on this wglCreateContextAttribsARB function that explain the arguments properly.

No, the specification says that the list of option/value pairs are terminated by a zero value, so one zero is enough.

However, I do terminate it with a double zero myself simply because I look at it as a list of option/value pairs, and the single terminating zero is only half a option/value pair. It is unnecessary, but I feels better to end it with a whole option/value pair since that is my view of it.

This topic is closed to new replies.

Advertisement