所以我因为没有放入&#39 ;;'而收到错误在括号之前{' {'就在主要部分和讨厌的部分之后,我已经尝试了迄今为止所做的任何事情(警告:我根本不是一个经验丰富的编码器)我甚至试图投入新的图书馆,但它不会起作用。我注意到虽然通过使用相同的int main和复制/粘贴它的类似代码,只有键盘功能是创建问题的那个....我真的无法理解...提前感谢你给予任何帮助:)
#include <GL/glut.h>
#include <math.h>
class Boxes
{
public: float x;
public: float y;
public: float w;
public: float h;
public: float r;
public: float g;
public: float b;
public: float i;
public: float j;
public: bool ActiveBox;
public: bool Horizontal;
void Draw()
{
glColor3f(r, g, b);
glRectf(x, y, x + w, y + h);
glColor3f(1, 1, 1);
glBegin(GL_LINE_LOOP);
glRectf(x, y, x + w, y + h);
glVertex2f(x, y);
glVertex2f(x, y + h);
glVertex2f(x + w, y + h);
glVertex2f(x + w, y);
glEnd();
}
void Outline(float r, float g, float b, float x, float y, float w, float h)
{
glColor3f(r, g, b);
glRectf(x, y, x + w, y + h);
glLineWidth(3);
glColor3f(1, 1, 1);
glBegin(GL_LINE_LOOP);
glVertex2f(x, y);
glVertex2f(x, y + h);
glVertex2f(x + w, y + h);
glVertex2f(x + w, y);
glEnd();
}
Boxes() { x = 0; y = 0; w = 0; h = 0; r = 0; g = 0; b = 0; i = 0; j = 0; ActiveBox = false; Horizontal = false; }
~Boxes() { x = 0; y = 0; w = 0; h = 0; r = 0; g = 0; b = 0; i = 0; j = 0; ActiveBox = false; Horizontal = false; }
};
Boxes PuzzlePieces[10];
int grid[6][6];
int d = 1;
int highlight = 1;
void Grid(float i, float j)
{
for (int i = 1; i < 7; i++)
{
for (int j = 1; j < 7; j++)
{
grid[i][j];
}
}
grid[1][1] = 1;
grid[1][2] = 1;
grid[1][3] = 1;
grid[1][4] = 1;
grid[1][5] = 1;
grid[1][6] = 1;
grid[2][1] = 1;
grid[2][2] = 1;
grid[2][3] = 0;
grid[2][4] = 1;
grid[2][5] = 1;
grid[2][6] = 1;
grid[3][1] = 0;
grid[3][2] = 1;
grid[3][3] = 1;
grid[3][4] = 1;
grid[3][5] = 0;
grid[3][6] = 0;
grid[4][1] = 1;
grid[4][2] = 1;
grid[4][3] = 0;
grid[4][4] = 1;
grid[4][5] = 1;
grid[4][6] = 0;
grid[5][1] = 0;
grid[5][2] = 0;
grid[5][3] = 1;
grid[5][4] = 1;
grid[5][5] = 1;
grid[5][6] = 0;
grid[6][1] = 0;
grid[6][2] = 0;
grid[6][3] = 1;
grid[6][4] = 0;
grid[6][5] = 1;
grid[6][6] = 0;
PuzzlePieces[1].w = d;
PuzzlePieces[1].h = 2 * d;
PuzzlePieces[1].g = 1;
PuzzlePieces[2].x = 1;
PuzzlePieces[2].w = d;
PuzzlePieces[2].h = 2 * d;
PuzzlePieces[2].g = 1;
PuzzlePieces[3].x = 2;
PuzzlePieces[3].w = d;
PuzzlePieces[3].h = 2 * d;
PuzzlePieces[3].g = 1;
PuzzlePieces[4].x = 3;
PuzzlePieces[4].w = 2 * d;
PuzzlePieces[4].h = d;
PuzzlePieces[4].b = 1;
PuzzlePieces[4].Horizontal = true;
PuzzlePieces[5].x = 4;
PuzzlePieces[5].y = 1;
PuzzlePieces[5].w = 2 * d;
PuzzlePieces[5].h = d;
PuzzlePieces[5].b = 1;
PuzzlePieces[5].Horizontal = true;
PuzzlePieces[6].x = 1;
PuzzlePieces[6].y = 3;
PuzzlePieces[6].h = d;
PuzzlePieces[6].w = 2 * d;
PuzzlePieces[6].b = 1;
PuzzlePieces[6].Horizontal = true;
PuzzlePieces[7].x = 3;
PuzzlePieces[7].y = 2;
PuzzlePieces[7].w = d;
PuzzlePieces[7].h = 3 * d;
PuzzlePieces[7].g = 1;
PuzzlePieces[8].x = 1;
PuzzlePieces[8].y = 2;
PuzzlePieces[8].w = 2 * d;
PuzzlePieces[8].h = d;
PuzzlePieces[8].r = 1;
PuzzlePieces[8].Horizontal = true;
PuzzlePieces[9].x = 2;
PuzzlePieces[9].y = 4;
PuzzlePieces[9].w = d;
PuzzlePieces[9].h = 2 * d;
PuzzlePieces[9].g = 1;
PuzzlePieces[10].x = 4;
PuzzlePieces[10].y = 3;
PuzzlePieces[10].w = d;
PuzzlePieces[10].h = 2 * d;
PuzzlePieces[10].g = 1;
}
void display(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity;
glTranslatef(2.5, 2.5, 0);
glBegin(GL_POLYGON);
glVertex2f(0, 0);
glVertex2f(0, 6);
glVertex2f(6, 6);
glVertex2f(6, 0);
glEnd();
for (int i = 0; i < 11; i++)
{
PuzzlePieces[i].Draw();
if (PuzzlePieces[i].ActiveBox == true)
{
PuzzlePieces[i].Outline;
}
}
glColor3f(1, 1, 1);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2f(0, 0);
glVertex2f(0, 6);
glVertex2f(6, 6);
glVertex2f(6, 0);
glEnd();
for (int i = 0; i < 8; i++)
{
PuzzlePieces[i].Draw;
}
glFlush();
}
void reshape (int w, int h)
{
float dx=600, dy=600;
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glOrtho(0.0, dx, 0.0, dy, 0, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27: exit(0); // escape ends the programm
case 'w':
if (highlight == 0)
{
PuzzlePieces[highlight].Outline = true;
}
if (highlight != 0)
{
PuzzlePieces[highlight].Outline = true;
PuzzlePieces[highlight - 1].Outline = false;
}
if (highlight == 8)
{
PuzzlePieces[0].Outline = true;
highlight = 0;
}
highlight++;
break;
glutPostRedisplay();
}
int main(int argc, char** argv)
**{**
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("DPSD - Graphics Arm Ex - 4");
Grid();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
答案 0 :(得分:0)
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27: exit(0); // escape ends the programm
case 'w':
if (highlight == 0)
{
PuzzlePieces[highlight].Outline = true;
}
if (highlight != 0)
{
PuzzlePieces[highlight].Outline = true;
PuzzlePieces[highlight - 1].Outline = false;
}
if (highlight == 8)
{
PuzzlePieces[0].Outline = true;
highlight = 0;
}
highlight++;
break;
glutPostRedisplay();
}
} // <= This is what you need.
int main(int argc, char** argv)