OpenGL Function Pointers

Hello Everyone - Whenever I compile my program I get a memory error, due to the fact that nearly half of the OpenGL function pointers point to 0x00000000. I have no idea why this is occurring as the same code worked in a separate project. Is there any generic reason this could be occurring or would some code be necessary for more information?

Any help is greatly appreciated.

The Error is:
"Unhandled exception at 0x00000000 in OpenGL Window.exe: 0xC0000005: Access violation."
Last edited on
closed account (o1vk4iN6)
Those functions aren't supported on your gpu ? Try updating the drivers.
Well the thing is they worked (and still do) in a different project with the same (or very similar) code. So they are supported by my GPU.
Last edited on
closed account (zb0S216C)
Are you trying to dereference a null function-pointer? Have you tried debugging? and have you tried checking for null before dereferencing?

Without the code counterpart, we'll be guessing to problem. Can you please post the code?

Wazzak
Last edited on
Here are the header and cpp files that I use to load the functions. They are similar to GL3W.

GL3SL.h
http://pastebin.com/qWAqMwF6

GL3SL.cpp
http://pastebin.com/2kM1hHZP

Everything up to and including glIsTexture has an address, but everything after and including glBlendColor does not - and this is after the load function completes.

There's nothing important in Shader.h, in fact I just removed its #include.

Basically I'm calling the function's like this:
Shader_VPTR = glCreateShader(GL_VERTEX_SHADER);
but glCreateShader is one of the functions that did not work and is pointing to address 0x00000000.
Last edited on
closed account (o1vk4iN6)
How do you create the context ?
Scatter a function like this throughout your code, might help you find your error. Has helped me with almost every openGL error I've ever had.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
inline void DefineGLErr(std::string caller)
{
	static int count = 0;
	count++;
	std::cout<<"DefineGLErr call number "<<count<<std::endl<<"Called in function: "<<caller<<std::endl;
	std::cout<<"RESULTS:"<<std::endl;
	GLenum err;
	while(1)
	{
		if((err = glGetError()) == GL_NO_ERROR){std::cout<<"No errors found"<<std::endl;break;}
		switch(err)
		{
		case(GL_INVALID_ENUM): std::cout<<"Invalid enum"<<std::endl; break;
		case(GL_INVALID_VALUE): std::cout<<"Invalid value"<<std::endl; break;
		case(GL_INVALID_OPERATION): std::cout<<"Invalid operation"<<std::endl; break;
		case(GL_STACK_OVERFLOW): std::cout<<"Stack overflow"<<std::endl; break;
		case(GL_STACK_UNDERFLOW): std::cout<<"Stack underflow"<<std::endl; break;
		case(GL_OUT_OF_MEMORY): std::cout<<"Out of memory"<<std::endl; break;
		case(GL_TABLE_TOO_LARGE): std::cout<<"Table to large"<<std::endl; break;
		default: std::cout<<"Error undefined"<<std::endl; break;
		}
	}
	std::cout<<"END OF ERRORS"<<std::endl<<std::endl;
}
@BlackSheep I will try that.

@xerzi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
bool CreateGLWindow(LPCWSTR title, int width, int height, int bitsperpel, bool fullscreen)
{
	GLuint PixelFormat; //Pixel Format
	WNDCLASS GLWindowClass; //Window Extended Class
	DWORD dwExStyle; //Extended Style
	DWORD dwStyle; //Window Style

	RECT GLWindowRect;

	GLWindowRect.left = (long)0; //Left boudary is set to 0
	GLWindowRect.right = (long)width; //Right Boundary is set to requested width
	GLWindowRect.top = (long)0; //Top boundary is set to 0 - this way the top left is coordinate 0
	GLWindowRect.bottom = (long)height; //bottom boundary is set to requested height

	GLWINDOW.Fullscreen = fullscreen; //sets teh requested fullscreen mode

	GLWINDOW.hInstance = GetModuleHandle(NULL); //set the window hInstance to the Module Handle

	GLWindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; //redraw horizontally vertically and has own DX
	GLWindowClass.lpfnWndProc = (WNDPROC)WndProc; //This is the LRESULT CALLBACK WndProc function
	GLWindowClass.cbClsExtra = 0; //no extra (console)? 
	GLWindowClass.cbWndExtra = 0; //no extra windot data..?
	GLWindowClass.hInstance = GLWINDOW.hInstance; //Sets the Window's hInstance to the one in the GLWindow object
	GLWindowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);  //CHANGE LATER
	GLWindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	GLWindowClass.hbrBackground = NULL; //No Background
	GLWindowClass.lpszMenuName = NULL; //No Menu;
	GLWindowClass.lpszClassName = L"SEWnd";

	if(!RegisterClass(&GLWindowClass)) //no longer Extended
	{
		MessageBox(NULL,ERROR_REGISTER_WINDOW_CLASS,ERROR_HEADER,MB_INFORM);
		return false;
	}

	if(GLWINDOW.Fullscreen)
	{
		DEVMODE dmScreenSettings; //Device Mode
		memset(&dmScreenSettings, NULL, sizeof(dmScreenSettings)); //Clear Memory for Variable
		dmScreenSettings.dmSize = sizeof(dmScreenSettings); //sets the size to that of the devmode structure
		dmScreenSettings.dmPelsWidth = width; //set fullscreen width
		dmScreenSettings.dmPelsHeight = height; //sets fullscreen height
		dmScreenSettings.dmBitsPerPel = bitsperpel; //sets bits per pixel 
		dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; //sets the fields

		if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) //attemtp to change display settings
		{
			if(MessageBox(NULL,ERROR_FULLSCREEN_MODE_GPU,NULL, MB_YESNO | MB_ICONEXCLAMATION) == IDYES) //add a definition for this
			{
				GLWINDOW.Fullscreen = false;
			}
			else
			{
				return false; //quit
			}
		}
	}

	if(GLWINDOW.Fullscreen) //If Fullscreen is supported according to previous if statement
	{
		dwExStyle = WS_EX_APPWINDOW; //modify the extended style for fullscreen
		dwStyle = WS_POPUP; //modify window style for fullscreen;
		ShowCursor(false); //optional - but recomended for fullscreen
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // defines the window Extended style //AD WS_DLGFRAME HERE TO FLIP LEFT AND RIGHT
		dwStyle = WS_OVERLAPPEDWINDOW; //defines the window style //CHANGE TO WS_BORDER TO REMOVE "_ [] X" buttons
	}

	AdjustWindowRectEx(&GLWindowRect, dwStyle, false, dwExStyle); //adjust the window to desired size

	if(!( GLWINDOW.hWnd = CreateWindowEx(dwExStyle, L"SEWnd", title, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, 0/*loc x*/, 0/*loc y*/, GLWindowRect.right - GLWindowRect.left, GLWindowRect.bottom - GLWindowRect.top, NULL, NULL, GLWINDOW.hInstance, NULL)))
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_CREATE_WINDOW,ERROR_HEADER,MB_INFORM);
		return false;
	}

	PIXELFORMATDESCRIPTOR pfd;

	memset(&pfd, NULL, sizeof(PIXELFORMATDESCRIPTOR)); //clear the pfd
	pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); //adjust pfd size
	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(!GL_Init()) //initialize opengl or opengl scene
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_INIT_OPENGL,ERROR_HEADER,MB_INFORM);
		return false;
	}
	Shader hiya("h.vert","h.frag"); //FIX LATER
	if(!(GLWINDOW.hDC = GetDC(GLWINDOW.hWnd)))
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_CREATE_DEVICE_CONTEXT,ERROR_HEADER,MB_INFORM);
		return false;
	}

	if(!(PixelFormat = ChoosePixelFormat(GLWINDOW.hDC, &pfd))) //attempt to choose the matching pixel format
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_MATCHING_PIXEL_FORMAT,ERROR_HEADER,MB_INFORM);
		return false;
	}

	if(!SetPixelFormat(GLWINDOW.hDC, PixelFormat, &pfd)) //attempt to set pixel format
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_SET_PIXEL_FORMAT,ERROR_HEADER,MB_INFORM);
		return false;
	}

	if(!(GLWINDOW.hRC = wgl_CreateContext(GLWINDOW.hDC))) //attempt to create the context
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_CREATE_RENDER_CONTEXT,ERROR_HEADER,MB_INFORM);
		return false;
	}

	if(!wgl_MakeCurrent(GLWINDOW.hDC, GLWINDOW.hRC)) //attempt to activate rendering context
	{
		CloseGLWindow();
		MessageBox(NULL,ERROR_ACTIVATE_OPENGL_CONTEXT,ERROR_HEADER,MB_INFORM);
		return false;
	}

	ShowWindow( GLWINDOW.hWnd, SW_SHOW); //show the window
	SetForegroundWindow(GLWINDOW.hWnd); //set the window to forground which inclreasses priority slightly
	SetFocus(GLWINDOW.hWnd); //select the window for keyboard focus
	//resize the gl scene    - glResize(width, height);

	//initglscene() or something like that

	return true;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_ACTIVATE:
		{
			if(!HIWORD(wParam)) //if not minimized
			{
				GLWINDOW.ActiveWindow = true;//FIX WHEN CLASS IS ADDED
			}
			else
			{
				GLWINDOW.ActiveWindow = false;
			}
		}
	case WM_SYSCOMMAND:
		{
			switch(wParam)
			{
			case SC_SCREENSAVE:   //Screen Saver
			case SC_MONITORPOWER: //Monitor Power Save Mode
			return false; //prevent both
			}
			break;
		}
	case WM_CLOSE:
		{
			PostQuitMessage(NULL);
			return false;
		}
	case WM_KEYDOWN: //Is a Key Pressed
		{
			GLWINDOW.KeyStates[wParam] = true; //change that keystate to pressed
			return false;
		}
	case WM_KEYUP: //Is a Key Released
		{
			GLWINDOW.KeyStates[wParam] = false; //change the keystate to unpressed
			return false;
		}
	case WM_SIZE:
		{
			//resize(LOWORD(lParam),HIWORD(lParam));
			return false;
		}
	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) //Entry Point for Thread 1
{
	GLWINDOW.Alive = true; //Possibly declare class here

	MSG Message;

	//POSSIBLE ASK IF FULLSCREEN IF FIRST RUN

	if(!CreateGLWindow(L"SETV", 640, 480, 32, false)) //should be 16bits per pel?
	{ 
		return false;
	}
	
	while(GLWINDOW.Alive)
	{
		if(PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) //If there is a message
		{
			if(Message.message == WM_QUIT)
			{
				GLWINDOW.Alive = false;
			}
			else
			{
				TranslateMessage(&Message);
				DispatchMessage(&Message);
			}
		}
		else //No Messages
		{
			if(GLWINDOW.ActiveWindow)
			{
				USE_ESCAPE_TO_QUIT
				else //RENDER
				{
					//Physics
					//Sound?
					RenderGLWindow();
					//Sound
				}
			}
			//F1 RESIZE THING MAYBE
		}
	}
	CloseGLWindow();
	return(Message.wParam); //Exit
}
Last edited on
As it turns out - I may not have created an OpenGL 3.x Context - However I still have no clue as to why so many of the function pointers are remaining NULL;
It seems GL_MAJOR_VERSION and GL_MINOR_VERSION are returning 0 in addition to the other errors
closed account (o1vk4iN6)
Well I don't see anything wrong, and if you say the same code works for another project I'd suggest comparing the compiler configurations. If not you can always take a look at the assembly and see why it's returning 0, although you should try to see the opengl error first as suggested above.
GetLastError() Returns "Function Failed"

But I'm restarting this project anyway to support OpenGL 4.3
The new project has the same issue...
I was just able to recreate the issue by moving the GL_Init(); to the main function rather than in a class like what is seen in Swiftless' tutorials.
Additionally glBlendColor (and everything afterwards) was a function that was not directly exported by the dll. Since I was using GetProcAddress I was recieving NULL pointers. After changing to wglGetProcAddress the functions returned their proper pointers.
Topic archived. No new replies allowed.