kullanırken birden çok hata Ben her şeyi var rağmen C++ kullanarak bir Snake oyunu, Opengl, SDL ve GL kullanarak oluşturmaya çalışıyorum Bağlantılı doğru bir hata yığını olsun, ben etrafa baktım ve bu hataların olduğunu buldum GL kullanırken oldukça yaygın olsa da neden "GL/freeglut.h" dahil olmak üzere "windows.h" dahil olmak üzere önlemleri aldığım gibi neden alıyorum? dahilgl
Hatalar şunlardır:
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
Ana 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;
};
Yılan 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);
};
Sorunuzu, * eksiksiz * hata çıktısını, düzenlenmemiş olarak eklemek için düzenleyin. Ayrıca, gösterilen kodda * nerede hata gördüğünüzü belirtin (örneğin bir yorum ekleyerek). Son olarak, yaptığınız hatalar "glAccum" hakkında bir şeyler söylüyor, ancak gösterdiğiniz kodun herhangi bir yerini aramadınız. Lütfen [Minimal, ** Tam ** ve Doğrulanabilir Örnek] (http://stackoverflow.com/help/mcve) oluşturmayı ve bize göstermeyi deneyin. –