wath determines opengl version

high everybody,

i download a sample code to learn opengl. when i build this sample the function “glGetString(GL_VERSION)” return “4.1.1”

but when i try to implement the code into my project the same function return “1.1.0” and many further functions doesn’t work anymore

here is the code :

LPCSTR szName = "Pez App";
    WNDCLASSEXA wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(0), 0, 0, 0, 0, szName, 0 };
    DWORD dwStyle = WS_SYSMENU | WS_VISIBLE | WS_POPUP;
    DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    RECT rect;
    int windowWidth, windowHeight, windowLeft, windowTop;
    HWND hWnd;
    PIXELFORMATDESCRIPTOR pfd;
    HDC hDC;
    HGLRC hRC;
    int pixelFormat;
    GLenum err;
    MSG msg = {0};
    LARGE_INTEGER previousTime;
    LARGE_INTEGER freqTime;

    wc.hCursor = LoadCursor(0, IDC_ARROW);
    RegisterClassExA(&wc);

    SetRect(&rect, 0, 0, PEZ_VIEWPORT_WIDTH, PEZ_VIEWPORT_HEIGHT);
    AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
    windowWidth = rect.right - rect.left;
    windowHeight = rect.bottom - rect.top;
    windowLeft = GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXSCREEN) / 2 - windowWidth / 2;
    windowTop = GetSystemMetrics(SM_CYSCREEN) / 2 - windowHeight / 2;
    hWnd = CreateWindowExA(0, szName, szName, dwStyle, windowLeft, windowTop, windowWidth, windowHeight, 0, 0, 0, 0);

    // Create the GL context.
    ZeroMemory(&pfd, sizeof(pfd));
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 24;
    pfd.cStencilBits = 8;
    pfd.iLayerType = PFD_MAIN_PLANE;

    hDC = GetDC(hWnd);
    pixelFormat = ChoosePixelFormat(hDC, &pfd);
	

    SetPixelFormat(hDC, pixelFormat, &pfd);
    hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);
    err = glewInit();
    if (GLEW_OK != err)
    {
        PezFatalError("GLEW Error: %s
", glewGetErrorString(err));
    }
    PezDebugString("OpenGL Version: %s
", glGetString(GL_VERSION));

and here is what i copy :


	int		PixelFormat;			// Holds The Results After Searching For A Match
	/*
	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);				// Black Background
	glClearDepth(1.0f);									// Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
	*/
	int bits = 16;
	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)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	}//*/;	
	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 = 32;
	pfd.iLayerType = PFD_MAIN_PLANE;

	if (!(hDC=GetDC(hMainWnd)))							// Did We Get A Device Context?
	{
		//System::getSingleton()->KillRenderWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

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

	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		//System::getSingleton()->KillRenderWindow();								// Reset The Display
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}
	if (!(hRC=wglCreateContext(hDC)))				// 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(hDC,hRC))					// 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 err;
	//glewExperimental = GL_TRUE;
    err = glewInit();
    if (GLEW_OK != err)
    {
		MessageBox(NULL,"Can't Activate The GLew.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;	
	}

any idea ? :s

Sure!
You have hit the fallback path and the driver turned to software rendering, probably because you have chosen a pixel format not supported by your graphics card. Usually ChoosePixelFormat() doesn’t work that way, and chooses the closest hardware accelerated pixel format, but for some reason this time it obeys your wish but in a software-mode.

pfd.cColorBits = 32;
pfd.cDepthBits = 32;

Microsoft documentation state that cColorBits it’s the number of bit per pixel excluded alpha.

The driver can’t find any RGBA format with 32bit for the color part only. Try 24.
Also cDepthBits not all video card support 32 bit zBuffers.

Use DescribePixelFormat to check it the pixel format selected by SelectPixelFormat have your requirement and use
wglChoosePixelFormatARB to get WGL_ACCELERATION_ARB
WGL_ACCELERATION_ARB’s value should be one of the values


WGL_NO_ACCELERATION_ARB                 0x2025
WGL_GENERIC_ACCELERATION_ARB            0x2026
WGL_FULL_ACCELERATION_ARB               0x2027

http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt

NONE! There is no graphics card on the market that supports 32-bit depth buffer for the default frame-buffer, as far as I know.

I looked around PixelFormat, I tried many samples code but no ones change the result i’m always locked to 1.1.0 version. I took care of the zBuffers, the cColorBits and the cDepthBits to don’t get up 24 bits…

I use visual studio and I compile my project as win console and from the console I create my “render window” is it the reason ?

Could you tell my what I must looking for … ?

Did you try each of these combinations without success :

pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;

pfd.iPixelType = PFD_TYPE_RGB;
pfd.cColorBits = 24;
pfd.cDepthBits = 24;

pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;

pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 0;

pfd.iPixelType = PFD_TYPE_RGB;
pfd.cColorBits = 24;
pfd.cDepthBits = 0;

pfd.iPixelType = PFD_TYPE_RGB;
pfd.cColorBits = 32;
pfd.cDepthBits = 0;

RESOLVED !

the problem was because i was using old opengl dlls

There isn’t an old dll and a new dll. The opengl32.dll comes with your OS and you should not change it.

http://www.opengl.org/wiki/FAQ#How_Does_It_Work_On_Windows.3F

I know that but i copied opengl dll from a sample folder to my app folder. I guess my soft was using it instead of the base ones

So i deleted these dlls and the problem was solved