Skip to main content
GameDev.net gamedev.net
🔒 Locked

Knowing my REAL OpenGL version - RESOLVED

Started by mikev Oct 3, 2014 at 12:50 AM 29 replies 9.7k views
Original Post
mikev
mikev

So I have an NVidia GeForce 525M. I am trying to use NVidia NSight debugger, as suggested by a user in one of my recent threads. For most of the capabilities of NSight, OpenGL 4.2 is required.

I looked up info on my graphics card: http://en.wikipedia.org/wiki/GeForce_500_Series#GeForce_500M_.285xxM.29_series

it looks like 4.2 is supported.

I also made use of GlView: http://www.realtech-vr.com/glview/ to check for 4.2 support.

While running NSight however, it complains that I have OpenGL 3. All my shaders use GLSL version 420 and they all work just fine. I have downloaded the latest drivers from my card as well.

I am using Glew 1.9.0 which should give me OpenGL 4.3 support...

Any idea why NSight would say I have OpenGL 3?

(edit)

I made use of the calls:

glGetIntegerv(GL_MAJOR_VERSION,*);

glGetIntegerv(GL_MINOR_VERSION,*);

both return 4.

So my card supports 4.2, my version of Glew supports 4.3, OpenGL queries say I have 4.4, and NSight tells me I have 3.0.. hahaha

L. Spiro
L. Spiro
What version is the OpenGL context you are creating?


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
mikev
mikev

Thanks, Spiro!

That's almost definitely the problem.. working on setting the OpenGL contexts version settings..


GLint attribs[] =
	{
	// Here we ask for OpenGL 4.2
	WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
	WGL_CONTEXT_MINOR_VERSION_ARB, 2,
	// Uncomment this for forward compatibility mode
	//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
	// Uncomment this for Compatibility profile
	//WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
	// We are using Core profile here
	WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
	0
	};


	if (!(mhRC = wglCreateContextAttribsARB(mhDC, 0, attribs)))	

This is throwing an access violation exception for me though.. trying to figure that out at the moment...

mikev
mikev

Alright, I'm at my wits end with this thing.

So, my understanding is that to create a GL Context with a specific version, I need to use wglCreateContextAttribsARB

This is a little messy because its an OpenGL extension, so OpenGL has to be initialized before you can use it - meaning you need to create a dummy GL Context just so you can initialize your desired context - weird but okay.

So I create a context as I was before, then call glewInit(), then delete my context, and create a new one with wglCreateContextAttribsARB. I pass in the following attributes:


GLint attribs[] =
{
// Here we ask for OpenGL 4.2
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};

This particular combination of attributes successfully creates a new context, but NSight still complains that the OpenGL version is 3.0.0. In addition, if I replace the WGL_CONTEXT_PROFILE_MASK_ARB value to be: "WGL_CONTEXT_CORE_PROFILE_BIT_AR" - my code throws no exceptions but my screen goes totally blank.

The context returned by wglCreateContextAttribsARB is non zero though, so I believe it did create a valid context.

Another peculiar observation, if I run in full screen mode, using Windows' ChangeDisplaySettings( ) function, NSight tells me the OpenGL version is 1.1...

In either case, it looks like my version number attributes are being ignored. sad.png

mikev
mikev

Here is my full context creation code (a bit sloppy I know)


BOOL GLContext::CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	
	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) NeHeWndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name


	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}

	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen=FALSE;		// Windowed Mode Selected.  Fullscreen = FALSE
			}
			else
			{
				// Pop Up A Message Box Letting User Know The Program Is Closing.
				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return FALSE;									// Return FALSE
			}
		}
	}

	if (fullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}


	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size

	// Create The Window
	if (!(mhWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}


	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		bits,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		8,											// 8 bit Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};
	
	if (!(mhDC=GetDC(mhWnd)))							// Did We Get A Device Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if (!(PixelFormat=ChoosePixelFormat(mhDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!SetPixelFormat(mhDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

        // create the dummy context so we can initialize GLEW
	if (!(mhRC=wglCreateContext(mhDC)))				// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	if(!wglMakeCurrent(mhDC,mhRC))					// Try To Activate The Rendering Context
	{
		KillGLWindow();								// Reset The Display
		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	 GLenum lError = glewInit();
    if (lError != GLEW_OK)
    {
		MessageBox(NULL,"Can't initialize GLEW.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return false;
    }
        // delete the dummy context
	wglDeleteContext(mhRC);

	const int attribList[] =
	{
		WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
		WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
		WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
		WGL_COLOR_BITS_ARB, 32,
		WGL_DEPTH_BITS_ARB, 24,
		WGL_STENCIL_BITS_ARB, 8,
		0,        //End
	};

	int pixelFormat;
	UINT numFormats;

	wglChoosePixelFormatARB(mhDC, attribList, NULL, 1, &pixelFormat, &numFormats);

	GLint attribs[] =
	{
		// Here we ask for OpenGL 4.2
		WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
		WGL_CONTEXT_MINOR_VERSION_ARB, 2,
		// Uncomment this for forward compatibility mode
		//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
		// Uncomment this for Compatibility profile
		WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
		// We are using Core profile here
		//WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
		0
	};

        // create the desired GL Context
	HGLRC CompHRC = wglCreateContextAttribsARB(mhDC, 0, attribs);
	if (CompHRC && wglMakeCurrent(mhDC, CompHRC))
		mhRC = CompHRC;

        // initialize models, etc.
	init();


	ShowWindow(mhWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(mhWnd);						// Slightly Higher Priority
	SetFocus(mhWnd);									// Sets Keyboard Focus To The Window
	resize(width, height);					// Set Up Our Perspective GL Screen

	return TRUE;									// Success
}

TheChubu
TheChubu

Can't you like, use SDL or something? Instead of doing the context initialization on your own I mean...

BTW, that card should support up to OpenGL 4.5.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"   My journals: dustArtemis ECS framework and 
Andrew Kabakwu
Andrew Kabakwu

Check if wglCreateContextAttribsARB is Null before using it.

And

if (CompHRC && wglMakeCurrent(mhDC, CompHRC))
mhRC = CompHRC;

Should be an if- else block


if (CompHRC && wglMakeCurrent(mhDC, CompHRC))
{
		mhRC = CompHRC;
}
else
{
 //Make current failed, so quit
}
Kaptein
Kaptein

Trying to make your own context creation is not going to be working for everyone. It's the first place I would look for "bugs" or workarounds. Using SDL is good advice.

EDIT: Also, seeing hDC in 2014, when does it end! You could support 3 OSes simply by using STL and SDL2. Not because you want to support all of them, but you never know.

mikev
mikev
Also, seeing hDC in 2014, when does it end!

hahaha, yeah I knew some people were going to be horrified when I posted that. Its some ancient code that originated from the old school NeHe tutorials.

I'm going to give SDL a shot and see if it fixed my problems!

Aks9
Aks9

I'm going to give SDL a shot and see if it fixed my problems!

I'm horrified with suggestions to use any of the library/wrapper for OpenGL. :(

It is not easy, but it is always better to understand what's happening under the hood than to be helplessly dependent on others.

Despite of its imperfections, OpenGL is still the best 3D graphics API for me, since I can do whatever I want having to install just the latest drivers and nothing more.

Of course, I need also a developing environment (read Visual Studio). Nobody wants to code in notepad and compile in command prompt.

Let's back to your problem. Before going any further revise your pixel format. It is not correct. The consequence is turning off HW acceleration and switching to OpenGL 1.1.

Tho following code snippet shows how to create valid GL context:


PIXELFORMATDESCRIPTOR pfd ;
    memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
    pfd.nSize  = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion   = 1; 
    pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;   
    pfd.iPixelType = PFD_TYPE_RGBA; 
    pfd.cColorBits = 32;
    pfd.cDepthBits = 24; 
    pfd.iLayerType = PFD_MAIN_PLANE;
 
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
 
if (nPixelFormat == 0)
    {
strcat_s(m_sErrorLog, LOGSIZE, "ChoosePixelFormat failed.\n");
return false;
    }   
DWORD error = GetLastError();
BOOL bResult = SetPixelFormat(hDC, nPixelFormat, &pfd);
if (!bResult)
    {
error = GetLastError();
strcat_s(m_sErrorLog, LOGSIZE, "SetPixelFormat failed.\n");
return false;
    }
 
HGLRC tempContext = wglCreateContext(hDC); 
wglMakeCurrent(hDC,tempContext);
 
int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, major,
WGL_CONTEXT_MINOR_VERSION_ARB, minor, 
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, // I suggest using debug context in order to know whats really happening and easily catch bugs
WGL_CONTEXT_PROFILE_MASK_ARB, nProfile, // nProfile = WGL_CONTEXT_CORE_PROFILE_BIT_ARB or WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
0
};
 
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB");
if(wglCreateContextAttribsARB != NULL)
{
context = wglCreateContextAttribsARB(hDC, 0, attribs);
}
wglMakeCurrent(NULL,NULL); 
wglDeleteContext(tempContext);
Kaptein
Kaptein

That is bad advice, aks9. There's nothing to learn when it comes to context creation, other than what a nightmare it can be if you have older (or buggy) drivers. I just look at the whole thing as risky, since if you take that code with you to other projects, one day one of the people trying the game/program out will simply not be able to run it because their driver requires a workaround.

You can do the same exact things with SDL or any other library, except you will have less grief during the process. Most of the time, anyways.

See 2:

http://richg42.blogspot.no/2014/05/things-that-drive-me-nuts-about-opengl.html

Really, why do this:

http://dantefalcone.name/tutorials/1a-windows-win32-window-and-3d-context-creation/

When SDL does it all for you in 10 lines of code. And it will work on every platform. ;)

EDIT: I downvoted you aks9, but I can't undo it. :( Your post is helpful, so I'm sorry.

Aks9
Aks9

"Father, forgive them, for they do not know what they are doing." sad.png

That is bad advice, aks9. There's nothing to learn when it comes to context creation, other than what a nightmare it can be if you have older (or buggy) drivers.

This is a typical agnostic claim. Everything is a source of knowledge. A rendering context creation is the first thing one should learn when starting with computer graphics.

But OK, I don't have time or will to argue about that.

Could you post a link, example or whatever to illustrate "the nightmare"? I've been creating GL contexts by myself about 18 years already and never had a problem. The problems could arise if you create GL 3.0+ context and hope everyone support it. Well, that is not a problem of drivers. Older drivers cannot assume what might happen in the future.

If the drivers are buggy, there is no workaround for the problem!

I just look at the whole thing as risky, since if you take that code with you to other projects, one day one of the people trying the game/program out will simply not be able to run it because their driver requires a workaround.

I really don't understand this.What kind of workaround? The way how a GL context is created is defined by the specification. Why risky?

You can do the same exact things with SDL or any other library, except you will have less grief during the process. Most of the time, anyways.

I want to have control in my hands so no intermediary stuff is welcome. It is harder at the start, but the filling of freedom is priceless.

This link is totally out of context. The guy is frustrated by something, but give no arguments for his claims.

Considering platform specific APIs for porting OpenGL, there was an initiative to make them unique. Khronos started development of EGL, but it is not adopted for desktop OpenGL yet.

EDIT: I downvoted you aks9, but I can't undo it. sad.png Your post is helpful, so I'm sorry.

Don't be sorry. That was your opinion and you have right to express it through (down)voting. Points means really nothing to me.

Forums should be the way to share knowledge and opinions. Some of them are true, some not. I hope right advices still prevail on the behalf of users.

Kaptein
Kaptein

Actually, for me it was because I was doing the same thing as you. But it didn't work on my brothers school-provided laptop. It had an older Intel model, and nothing I did worked. In the end I just gave up and used an existing library.

mikev
mikev

Thanks so much for your suggestions, Aks9 and Kaptein!

Before seeing your suggestions on Pixel format, Aks9, I gave SDL a quick spin. I used the following example code:

https://github.com/meandmark/SDLOpenGLIntro/tree/sdl2

Inside GameApp.cpp I modified the context creation to use a paticular version:


void GameApp::InitializeSDL(Uint32 width, Uint32 height, Uint32 flags)
{
    int error;
    
    error = SDL_Init(SDL_INIT_EVERYTHING);
    // Turn on double buffering.
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    // Set Context version number.
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); 
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 

    // Create the window
    mainWindow = SDL_CreateWindow("SDL2 OpenGL Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
    mainGLContext = SDL_GL_CreateContext(mainWindow);
                        
}

I even tried older versions (like 2.0) and NSight still insists my OpenGL version is 3.0.

I would try your suggestions regarding PixelFormat, Aks9, but if SDL is failing to set the version it seems to me something else might be going on.

I wonder if I should call shenanigans on NSight, or on my graphics hardware.. really this is so frustrating!

mark ds
mark ds

I answered a similar question a while ago: http://www.gamedev.net/topic/661317-help-with-using-wgl/?view=findpost&p=5182765

It shows all the necessary steps to properly create a context:

create a dummy window

select a pixelformat

create a GL rendering context

call glewInit()

destroy the GL rendering context

destroy window

then create a new window

choose a ARB pixel format

select the pixel format

create a ARB rendering context

You should then be good to go.

However, it could be that NSight has a bug in it...

Aks9
Aks9

I even tried older versions (like 2.0) and NSight still insists my OpenGL version is 3.0.

What does glGetString(GL_VERSION) say?

That should returned the highest GL version supported by the driver.

Specification is clear:

The attribute names WGL_CONTEXT_MAJOR_VERSION_ARB and WGL_CONTEXT_MINOR_VERSION_ARB request an OpenGL context supporting the specified version of the API. If successful, the context returned must be backwards compatible with the context requested.

So, if you require GL 2.0 context, you could legitimately get GL 4.4 compatibility profile, since it is backward compatible with 2.0.

P.S. My browser or the engine that powers up this site, or both in a combination, are "lucid". All I typed down was in the same font and size, but the outcome is ridiculous. dry.png

TheChubu
TheChubu




This is a typical agnostic claim.
... the fuck?
"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"   My journals: dustArtemis ECS framework and 
samoth
samoth
create a dummy window
select a pixelformat
create a GL rendering context
call glewInit()
destroy the GL rendering context
destroy window

then create a new window
choose a ARB pixel format
select the pixel format

create a ARB rendering context

I am not even sure this is 100% legitimate, although I guess that it will probably work (or, possibly, it will "work").

There is no good reason why creating a context should require an already existing one (there's no good reason for a couple of things related to OpenGL contexts, though), but to the letter of the rulebook, you can only legitimately call GL and WGL functions if you have a valid context, and any function pointers that you have obtained are valid for only that context, thus they become invalid once you delete the context (although WGL guarantees as a "non-standard feature" that function pointers for contexts that have the same pixel format are all the same and interchangeable).

Which means that the sequence delete dummy context - delete dummy window - create new window - call WGL function to create new context is at least in theory bad mojo. I don't know if it factually matters, but my context creation code (which seems to work fine) only deletes the dummy stuff after creating the real one (and only initializes all function pointers on that one, all it does with the dummy context is pull the function pointer for wglCreateContextAttribsARB). In theory, destroying a context could unload the shared library your function pointers refer to (I highly doubt that, but who can tell) or it could do some other undefined or implementation-defined stuff, like give you a 3.x compatibility context or such when you create another context (or, a black screen).

That said, context creation is ugly stuff, avoid it if you have any possibility of doing so. I didn't want an external dependency like SDL back then, and also shared contexts looked like an attractive thing (what a mistake!), so all in all this looked like a valid reason to write my own. Father they do not know what they are doing, indeed.

Don't do that. Just use a library that works.

mikev
mikev

Thanks for all the suggestions and analysis, guys.

What does glGetString(GL_VERSION) say?

I used this information: https://www.opengl.org/wiki/Get_Context_Info

My headers don't seem to include the above function so I use this:

glGetIntegerv(GL_MAJOR_VERSION,*);

glGetIntegerv(GL_MINOR_VERSION,*);

Both of them return 4, (although I haven't tried this when using context initialization with SDL, will give that a shot). So it looks like it is creating an OpenGL 4.4 context, but I don't fully trust anything at the moment, with all these contradictory results.

I think I need to start more thoroughly questioning NSight and where it is reading its version information. Not sure what else it could be...

Could it possibly be my OpenGL headers that are somehow screwing things up?

mark ds
mark ds

Could it possibly be my OpenGL headers that are somehow screwing things up?

They shouldn't affect NSight. But are you using the latest headers anyway? You need glext.h & wglext.h https://www.opengl.org/registry/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.