Glew won't initialize

I'm trying to make a simple opengl program. I've just started it but am already running into a problem. The code compiles and runs but glew keeps failing to initilize. It says, "Missing GL Version". I've tried to figure out what I'm doing wrong but can't seem to think of anything. My code so far is:
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
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <glm.hpp>
#include <IL/il.h>
#include <IL/ilu.h>
#include <iostream>
#include <cmath>

#define FPS 30

using namespace std;
using namespace glm;

void Loop(int);

void display(void)
{

}


void key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case 27 :
        case 'q':
            exit(0);
            break;
    }
}

void Init()
{
	float TriangleVerticies[] =
	{
        1, -1, 0,
        -1, -1, 0,
        0, 1, 0
	};
	GLuint tvID;
	glGenBuffers(1, &tvID);
	glBindBuffer(GL_ARRAY_BUFFER, tvID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(TriangleVerticies), TriangleVerticies, GL_STATIC_DRAW);
}

int main( int argc, char* argv[] )
{
    glutInit(&argc, argv);
    glutInitContextVersion(3, 3);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(0,0);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);

    GLenum GlewINIT = glewInit();
    if ( GlewINIT != GLEW_OK )
    {
        cout<<"Glew failed to Initialize. Error: "<<glewGetErrorString(GlewINIT)<<endl;
        exit(0xbad);
    }

    Init();

    glutCreateWindow("Name");

    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    Loop(0);

    glutMainLoop();

    return 0;
}

void Loop(int Val)
{
    display();

    glutTimerFunc( 1000/FPS, Loop, 0 );
}


Edit:
Nvm; I figured it out. I had to create the window before calling glewinit
Last edited on
Just curious, if I want to make my own classes for my shaders (matricies, vectors, ect.), how do I add them to my shaders since they are stored in .txt files? Do I just write #include "Whatever.h"?
Topic archived. No new replies allowed.