PDA

View Full Version : wglCreateContextAttribsARB identifier not found



kalkas
07-26-2011, 09:26 AM
hi

i'm trying to create an OpenGL 3.1 Context( C++, Windows ) and
i'm getting an error:
error C3861: 'wglCreateContextAttribsARB': identifier not found

i have included all the nessecary headers:

#include "gl/glew.h"
#include "gl/wglew.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <glext.h>
#include <wglext.h>
#include <windows.h>

i'm using the tutorial from here:

http://www.opengl.org/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_%28C%2B%2B/Win%29

and here's my initilization:

GLuint PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;

fullscreen = _fullscreen;

hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";

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

if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&amp;dmScreenSettings,0,sizeof(dmScreenSettings ));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;


if (ChangeDisplaySettings(&amp;dmScreenSettings,CDS_FULLS CREEN)!=DISP_CHANGE_SUCCESSFUL)
{

if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","XYZ3D",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE;
}
else
{
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE;
}
}
}

if (fullscreen)
{
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
ShowCursor(TRUE);
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}

AdjustWindowRectEx(&amp;WindowRect, dwStyle, FALSE, dwExStyle);


if (!(hWnd=CreateWindowEx(dwExStyle,
"OpenGL",
title,
dwStyle |
WS_CLIPSIBLINGS |
WS_CLIPCHILDREN,
0, 0,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
NULL,
NULL,
hInstance,
NULL)))
{
closeWindow();
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bits,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};

if (!(hDC=GetDC(hWnd)))
{
closeWindow();
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if (!(PixelFormat=ChoosePixelFormat(hDC,&amp;pfd)))
{
closeWindow();
MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if(!SetPixelFormat(hDC,PixelFormat,&amp;pfd))
{
closeWindow();
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

HGLRC tempContext;

if (!(tempContext=wglCreateContext(hDC)))
{
closeWindow();
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if(!wglMakeCurrent(hDC,tempContext))
{
closeWindow();
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if (glewInit() != GLEW_OK)
{
MessageBox(NULL,"Cannot initialize Glew","XYZ3D",MB_OK|MB_ICONEXCLAMATION);
}

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

//PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = null;

if(wglewIsSupported("WGL_ARB_create_context") == 1)
{
hRC = wglCreateContextAttribsARB(hDC,0, attribs); //<<-----------Here //is the error
wglMakeCurrent(NULL,NULL);
wglDeleteContext(tempContext);
wglMakeCurrent(hDC, hRC);
MessageBox(NULL,"OpenGL Rendering Context v3.1","XYZ3D",MB_OK|MB_ICONEXCLAMATION);
}
else
{ //It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before)
hRC = tempContext;
MessageBox(NULL,"OpenGL Rendering Context v2.1","XYZ3D",MB_OK|MB_ICONEXCLAMATION);
}

ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
XYZ3DRenderer::Refresh(width, height);

return TRUE;

thanks in advance