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