Я пытаюсь создать игру Snake с C++, используя Opengl, SDL и GL, хотя у меня все правильно. Я правильно понял, что получаю кучу ошибок при построении, я огляделся и обнаружил, что эти ошибки довольно распространенный при использовании GL, хотя я не могу точно определить, почему я получаю их, поскольку я принял меры предосторожности, такие как включение «windows.h», прежде чем включать «GL/freeglut.h», кто-нибудь может помочь?Несколько ошибок при использовании gl
Ошибки входят:
error C2144: syntax error : 'void' should be preceded by ';'
Error C2144 syntax error: 'void' should be preceded by ';' OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C2182 'APIENTRY': illegal use of type 'void' OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C2146 syntax error: missing ';' before identifier 'glAccum' OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C2144 syntax error: 'void' should be preceded by ';' OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C2182 'APIENTRY': illegal use of type 'void' OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Error C2146 syntax error: missing ';' before identifier 'glAccum' OpenGLTutorial c:\program files (x86)\windows kits\8.1\include\um\gl\gl.h 1157
Главная каст
#ifdef __MINGW32__
#include <windows.h>
#endif
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/freeglut.h>
#include <SDL2/SDL.h>
#include <time.h>
#include "SnakeGame.hpp"
int main(void) {
srand(time(NULL));
SnakeGame *f = new SnakeGame();
f->run();
return 0;
}
Arena.hpp
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/freeglut.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "Obstacle.hpp"
#include "Fruit.hpp"
#include "Snake.hpp"
#include "Font.hpp"
class Arena {
public:
Arena(void);
virtual ~Arena(void);
void update(void);
inline void draw(void);
Snake *snake;
private:
float rot;
unsigned int score;
Font *font;
inline void correct_elements(void);
void drawRainbowTriangle(void);
void correct_fruit(void);
void correct_obstacle(void);
void correct_snake(void);
bool is_snake_dead(void);
bool is_snake_eating(void);
Obstacle *obstacle;
Fruit *fruit;
};
Element.hpp
#include <iostream>
#include <ostream>
#include <GL/freeglut.h>
#include <GL/gl.h>
class Element {
public:
Element();
virtual void draw() = 0;
int getX();
int getY();
void setX(int it);
void setY(int it);
void display();
protected:
int x;
int y;
};
Font.hpp
#include <GL/freeglut.h>
#include <string.h>
class Font {
public:
void bitmap_output(int x, int y, const char *string, void *font = GLUT_BITMAP_TIMES_ROMAN_24);
private:
};
Fruit.hpp
#include <GL/freeglut.h>
#include <GL/gl.h>
#include "Element.hpp"
class Fruit : public Element {
public:
void draw();
};
Game.hpp
include <SDL2/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
class Game {
public:
Game();
~Game();
virtual void run()=0;
int get_score();
void set_score(int s);
bool paused;
private:
protected:
SDL_Renderer* displayRenderer;
SDL_Window* displayWindow;
SDL_RendererInfo displayRendererInfo;
};
Snake.hpp
#include <iostream>
#include <list>
#include <GL/gl.h>
#include <GL/freeglut.h>
#include "Element.hpp"
enum Dir {UP, DOWN, RIGHT, LEFT};
class Body : public Element {
public:
void draw() {
glColor3ub(0, 0, 255);
glPushMatrix();
glTranslatef(x, y, -y);
glutSolidCube(1);
glPopMatrix();
}
};
class Snake {
public:
Snake();
~Snake();
void update(void);
void draw(void);
void grow(int size);
void setDir(Dir direction);
std::list<Body> body;
std::list<Body>::iterator iter;
private:
Dir dir;
};
Snake game.hpp
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include "Arena.hpp"
#include "Game.hpp"
class SnakeGame : public Game {
public:
SnakeGame();
virtual ~SnakeGame();
void run();
private:
bool is; //is the game running
Arena arena;
void keyboard(const SDL_Event &event);
};
Пожалуйста, отредактируйте ваш вопрос, чтобы включить * полный * выход ошибки, неотредактированный. Также укажите * где * в показанном коде вы получите ошибки (например, добавив комментарий). Наконец, ошибки, которые вы показываете, говорят что-то о 'glAccum', но вы не называете это нигде в коде, который вы показываете. Попробуйте создать [Минимальный, ** Полный ** и Подтверждаемый пример] (http://stackoverflow.com/help/mcve) и покажите нам. –