View Full Version : OpenGL Programming Guide 8th Edition: Can't find GLEW functions

06-02-2014, 06:56 AM
Hi all,

I've just started working through the OpenGL Programming Guide 8th Edition and it's really is a headache getting everything to work!

I've managed to get most things to work, except for, I believe, GLEW functions - such as; glGenVertexArrays, glBindVertexArray, glGenBuffers and a host of others.


// Contains our "free methods" variables etc.

// Namespaces give our "free methods" some ownership

// We need to tell GLUTCallbacks about our HelloGL class, but HelloGL already #includes "GLUTCallsbacks.h", so if we used
// #include "HelloGL.h" it would create a circular dependency, which will cause the build to fail. The reason for this is because GLUTCallbacks is compiled first, so it will require HelloGL.h, but
// won't be able to find it because
#pragma once

class triangles; // Forward declare HelloGL

namespace GLUTCallbacks // all of the enclosed code is stored in the GLUTCallbacks namespace
void Init(triangles* gl); // We need to be able to access the HelloGL class, so we'll store the HelloGL reference in a pointer called gl and pass it to the Init function inside our namespace
void Display();

triangles.h (Tried that ifdef APPLE thing, found it on google, but didn't make it work):

#pragma once // Makes sure the files are included only once

#ifdef __APPLE__
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArrays glBindVertexArraysAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE

#include <Windows.h> // Required for OpenGL on Windows
#include "GL3\gl3.h"
#include <gl/GL.h> // OpenGL
#include <gl/GLU.h> // OpenGL Utilities
#include "GL/glew.h"
#include "GL/glut.h"
#include "GL\freeglut.h" // freeglut library
#include "GLUTCallbacks.h"
#include <iostream>
#include "vgl.h"
#include "LoadShaders.h"

using namespace std;

class triangles
triangles(int argc, char* argv[]);

void Display();
void init(void);



// Contains out "free methods"
#include "GLUTCallbacks.h" // "" means the file is in the curent directory, <> means the file is in the system32 folder
#include "triangles.h" // This needs to be included so we know what the HelloGL class is

namespace GLUTCallbacks // All of the enclosed code is stored in the GLUTCallbacks namespace
namespace // This is an anonymous namespace, it means nothing can access any of the code inside the namespace, meaning nothing can access the HelloGL pointer, gl, except the code within the GLUTCallsbacks
// namespace.
triangles* triangleS = nullptr; // Initalises the pointer to null so it's not pointing at any memory.

void Init(triangles* tri)
triangleS = tri;

// This Display() method will simply call the display() method within the HelloGL class. We're doing this so we can have a nice structure (our HelloGL class), and just wrap the class methods up in free methods
// so that freeglut has access to them.
void Display()
if(triangleS != nullptr) // If the address of the helloGL pointer is not null, run the display function.



#include "triangles.h"

int main(int argc, char* argv[]) {
triangles * game = new triangles(argc, argv);
//Creates an instance of our game
return 0;
//Assumes a sucessful exit if our game exits and we make it to this


// triangles.cpp
#include "triangles.h"

enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;

triangles::triangles(int argc, char* argv[])
GLUTCallbacks::Init(this); // Sets the GLUTCallbacks pointer to this instance of the triangles class.
glutInit(&argc, argv);
glutInitWindowSize(512, 512);
glutInitContextVersion(4, 3);
glutCreateWindow("Simple OpenGL Program");

//if (glewInit())
// cerr << "Unable to initialize GLEW ... exiting" << endl;
// exit(EXIT_FAILURE);



// init
void triangles::init(void)
glGenVertexArrays(NumVAOs, VAOs);
GLfloat vertices[NumVertices][2] = {
{ -0.90, -0.90 }, // Triangle 1
{ 0.85, -0.90 },
{ -0.90, 0.85 },
{ 0.90, -0.85 }, // Triangle 2
{ 0.90, 0.90 },
{ -0.85, 0.90 }
glGenBuffers(NumBuffers, Buffers);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, "triangles.vert" },
{ GL_FRAGMENT_SHADER, "triangles.frag" },
GLuint program = LoadShaders(shaders);
glVertexAttribPointer(vPosition, 2, GL_FLOAT,
// display
void display(void)
glDrawArrays(GL_TRIANGLES, 0, NumVertices);

// main
//int main(int argc, char** argv)
// glutInit(&argc, argv);
// glutInitDisplayMode(GLUT_RGBA);
// glutInitWindowSize(512, 512);
// glutInitContextVersion(4, 3);
// glutInitContextProfile(GLUT_CORE_PROFILE);
// glutCreateWindow(argv[0]);
// if (glewInit())
// {
// cerr << "Unable to initialize GLEW ... exiting" << endl;
// exit(EXIT_FAILURE);
// }
// init();
// glutDisplayFunc(display);
// glutMainLoop();

The GLUTCallbacks is from my uni course that I'm doing, but we never went through the redbook so it's a different way of setting things up that I'm normally used to. I think it's still required here though, but not 100% sure. Just doing what I know.

There are obviously a lot of other imminent errors but right now I just need GLEW to work. Thanks a lot to anyone that can help!

Here are the file directories:

(Using Visual Studio 2012)



triangles\triangles (part 1):

postimg dot org/image/yzcdnznsn/

triangles\triangles (part 2):

postimg dot org/image/k9w7wieil/

06-02-2014, 09:18 AM
Have you included GLEW's header files? Why is glewInit() commented?
If you haven't got GLEW click here (http://glew.sourceforge.net/).