Opengl-无法识别GLfloat

Opengl - GLfloat not being recognized

本文关键字:GLfloat 识别 Opengl-      更新时间:2023-10-16

由于这个类声明有一些问题,我试图为Dijktra最短路径算法的openGL实现创建节点。getX()、getY()和getZ()方法导致错误:

错误:ISO C++禁止声明没有类型的"getX"

我在ubuntu-linux上使用g++进行编译。命令:g++-lglut-lGLU-lGL项目测试.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];

我认为问题出在预处理器宏中。我是openGL的新手,对c++也有点陌生,所以任何建议都很好,但我真正想知道的是我为什么会出错。

您需要

#include <GL/gl.h>

在包括OpenGL扩展的头之前。

如果您有

#include <GL/glut.h>

那么您不应该需要GL/GL.h或GL/glu.h,尽管您可能必须将cstdlib放在GL/glus.h

之前