Knowing my REAL OpenGL version - RESOLVED

Started by
29 comments, last by 21st Century Moose 9 years, 6 months ago

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

Advertisement
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

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...

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

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
}

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 Making a Terrain Generator

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
}

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.

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!

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);

This topic is closed to new replies.

Advertisement