Opengl - GLfloat not being recognized

Matt Source

Having some trouble with this class declaration, Im trying to create nodes for an openGL implementation of Dijktra's shortest path algorithm. the getX(), getY(), getZ() methods cause an error:

error: ISO C++ forbids declaration of ‘getX’ with no type

Im compiling with g++ on ubuntu linux. Command: g++ -lglut -lGLU -lGL projecttest.c

#include <cstdarg>
#include <cstdio>
#include <GL/glut.h>
#include <GL/glu.h>
#include <cstdlib> 
#include <iostream>
#define kWindowWidth 800
#define kWindowHeight 600 
#define NUM_NODES 3

using namespace std;

class Node {
    private: 
        GLfloat x, y, z;
        int numLinks;
        Node *links[];
    public: 
        Node(GLfloat x, GLfloat y, ...);
        ~Node();
        GLfloat getX();
        GLfloat getY();
        GLfloat getZ() {return 0.0f;}
} Node;

Node nodes_g[NUM_NODES];

I think the problem is in the preprocessor macros. Im new to openGL and somewhat new to c++ so any advice is good, but what I really want to know is why im getting the error.

c++openglglut

Answers

answered 7 years ago Ben Voigt #1

You need

#include <GL/gl.h>

before including headers for OpenGL extensions.

answered 7 years ago fintelia #2

If you have

#include <GL/glut.h>

Then you should not need GL/gl.h or GL/glu.h, although you may have to put cstdlib before GL/glut.h

comments powered by Disqus