glewInit() not working

Currently I am trying to create a template project for Visual Studio but glewInit() doesn't seem to work for the life of it. When I use glGetError() I get 1282.

I created an empty project and modified these settings.

1
2
Additional Include Directiories
C:\OpenGL\glfw-3.2.bin.WIN32\include;C:\OpenGL\glew-1.13.0\include;%(AdditionalIncludeDirectories)


1
2
Additional Library Directories
C:\OpenGL\glfw-3.2.bin.WIN32\lib-vc2015;C:\OpenGL\glew-1.13.0\lib\Release\Win32;%(AdditionalLibraryDirectories)


1
2
Additional Dependencies
opengl32.lib;glew32.lib;glfw3.lib;%(AdditionalDependencies)



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
Main.cpp
#include <iostream>
#include <GL\glew.h>
#include <GLFW\glfw3.h>

//#define GLEW_STATIC							//will put glew32.dll in game exe
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
#define WINDOW_TITLE "OpenGL Project"

int main(int argc, char *argv[]) {

	//Init GLFW
	if (!glfwInit()) {

		return -1;

	}

	//Init GLEW
	if (glewInit() != GLEW_OK) {

		return -2;

	}

	//Create GLFW Window
	GLFWwindow* game_window;

	glfwWindowHint(GLFW_VERSION_MAJOR, 3);						//Tell the game that OpenGL V3.3 is needed; Major then Minor
	glfwWindowHint(GLFW_VERSION_MINOR, 3);

	game_window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, NULL, NULL);

	if (!game_window) {

		glfwTerminate();
		return -3;

	}

	//Setup Window
	int window_width, window_height;
	glfwGetFramebufferSize(game_window, &window_width, &window_height);				//get window sites

	glViewport(0, 0, window_width, window_height);					//set coordinates to top left (0,0); and set width and height to actual window width and height
	glfwMakeContextCurrent(game_window);							//make game_window the current focused window

																	//Loop game
	while (true) {

		glClear(GL_COLOR_BUFFER_BIT);

		//Poll and Process events
		glfwPollEvents();

		//Update

		//Swap Buffers
		glfwSwapBuffers(game_window);

		//Check if game should quit;; X Button is pressed
		if (glfwWindowShouldClose(game_window)) {

			break;

		}

	}

	//Quit Game
	glfwTerminate();
	return 0;

}
Last edited on
GLEW requires an active OpenGL context. You don't have one when you call glewInit. Move the call to after the window is created.

http://www.glfw.org/docs/latest/context_guide.html
Thanks alot, but to get it to work I had to move glewInit() to after window creation and add glfwMakeContextCurrent(game_window); before glewInit().
You say "but" as if the documentation linked didn't spell it out for you. It does. ;)
Topic archived. No new replies allowed.