Ich versuche, ein Snake-Spiel mit C++ mit OpenGL, SDL und GL zu erstellen, obwohl ich alles richtig verknüpft habe Ich bekomme einen Haufen von Fehlern beim Bauen, ich habe mich umgesehen und festgestellt, dass diese Fehler sind ziemlich häufig, wenn ich GL benutze, obwohl ich nicht genau zu bestimmen vermag, warum ich sie bekomme, da ich die Vorsichtsmaßnahmen getroffen habe, einschließlich "windows.h", bevor "GL/freeglut.h" eingeschlossen wurde, kann mir jemand helfen?Mehrere Fehler bei der Verwendung gl
Fehler enthalten sind:
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
Haupt cpp
#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);
};
Bitte bearbeiten Sie Ihre Frage, um die * komplette * Fehlerausgabe, unbearbeitet, einzuschließen. Zeigen Sie auch * wo * in dem angezeigten Code die Fehler erhalten (zum Beispiel durch Hinzufügen eines Kommentars). Zu guter Letzt sagen die Fehler, die Sie zeigen, etwas über 'glAccum', aber Sie rufen das nirgendwo in dem Code auf, den Sie zeigen. Bitte versuchen Sie, ein [minimales, ** vollständiges ** und verifizierbares Beispiel] (http://stackoverflow.com/help/mcve) zu erstellen und zeigen Sie uns. –