madlen611 Temat założony przez niniejszego użytkownika |
OpenGL problem » 2014-05-25 14:44:22 Witam, skopiowałam kod czwartego tematu, by zobaczyć czy działa, pojawiają się komunikaty: 43:error: expected unqualified-id before '=' token In function 'void Display()': 84: error: expected primary-expression before ')' token In function 'void Reshape(int, int)': 173: error: expected primary-expression before ',' token 173: error: expected primary-expression before ')' token 178: error: expected primary-expression before ',' token 178 error: expected primary-expression before ')' token 182: error: expected primary-expression before ',' token 182: error: expected primary-expression before ')' token o jakie primary-expression może chodzić?
#include <glut.h> #include <stdlib.h>
enum { FULL_WINDOW, ASPECT_1_1, WIRE_SPHERE, WIRE_CONE, WIRE_CUBE, WIRE_TORUS, WIRE_DODECAHEDRON, WIRE_TEAPOT, WIRE_OCTAHEDRON, WIRE_TETRAHEDRON, WIRE_ICOSAHEDRON, EXIT };
int aspect = FULL_WINDOW;
int object = WIRE_SPHERE;
const GLdouble left = - 10.0; const GLdouble right = 10.0; const GLdouble bottom = - 10.0; const GLdouble top = 10.0; const GLdouble near = 50.0; const GLdouble far = 70.0;
GLfloat scale = 1.0;
GLfloat rotatex = 0.0; GLfloat rotatey = 0.0;
GLfloat translatex = 0.0; GLfloat translatey = 0.0;
int button_state = GLUT_UP;
int button_x, button_y;
void Display() { glClearColor( 1.0, 1.0, 1.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0, 0, -( near + far ) / 2 ); glTranslatef( translatex, translatey, 0.0 ); glScalef( scale, scale, scale ); glRotatef( rotatex, 1.0, 0, 0 ); glRotatef( rotatey, 0, 1.0, 0 ); glColor3f( 0.0, 0.0, 0.0 ); switch( object ) { case WIRE_SPHERE: glutWireSphere( 1.0, 20, 10 ); break; case WIRE_CONE: glutWireCone( 1.0, 2.0, 20, 10 ); break; case WIRE_CUBE: glutWireCube( 1.0 ); break; case WIRE_TORUS: glutWireTorus( 0.2, 1, 10, 20 ); break; case WIRE_DODECAHEDRON: glutWireDodecahedron(); break; case WIRE_TEAPOT: glutWireTeapot( 1.0 ); break; case WIRE_OCTAHEDRON: glutWireOctahedron(); break; case WIRE_TETRAHEDRON: glutWireTetrahedron(); break; case WIRE_ICOSAHEDRON: glutWireIcosahedron(); break; } glFlush(); glutSwapBuffers(); }
void Reshape( int width, int height ) { glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); if( aspect == ASPECT_1_1 ) { if( width < height && width > 0 ) glFrustum( left, right, bottom * height / width, top * height / width, near, far ); else if( width >= height && height > 0 ) glFrustum( left * width / height, right * width / height, bottom, top, near, far ); } else glFrustum( left, right, bottom, top, near, far ); Display(); }
void Keyboard( unsigned char key, int x, int y ) { if( key == '+' ) scale += 0.1; else if( key == '-' && scale > 0.1 ) scale -= 0.1; Reshape( glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ) ); }
void SpecialKeys( int key, int x, int y ) { switch( key ) { case GLUT_KEY_LEFT: rotatey -= 1; break; case GLUT_KEY_UP: rotatex -= 1; break; case GLUT_KEY_RIGHT: rotatey += 1; break; case GLUT_KEY_DOWN: rotatex += 1; break; } Reshape( glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ) ); }
void MouseButton( int button, int state, int x, int y ) { if( button == GLUT_LEFT_BUTTON ) { button_state = state; if( state == GLUT_DOWN ) { button_x = x; button_y = y; } } }
void MouseMotion( int x, int y ) { if( button_state == GLUT_DOWN ) { translatex += 1.1 *( right - left ) / glutGet( GLUT_WINDOW_WIDTH ) *( x - button_x ); button_x = x; translatey += 1.1 *( top - bottom ) / glutGet( GLUT_WINDOW_HEIGHT ) *( button_y - y ); button_y = y; glutPostRedisplay(); } }
void Menu( int value ) { switch( value ) { case FULL_WINDOW: aspect = FULL_WINDOW; Reshape( glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ) ); break; case ASPECT_1_1: aspect = ASPECT_1_1; Reshape( glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ) ); break; case WIRE_SPHERE: object = WIRE_SPHERE; Display(); break; case WIRE_CONE: object = WIRE_CONE; Display(); break; case WIRE_CUBE: object = WIRE_CUBE; Display(); break; case WIRE_TORUS: object = WIRE_TORUS; Display(); break; case WIRE_DODECAHEDRON: object = WIRE_DODECAHEDRON; Display(); break; case WIRE_TEAPOT: object = WIRE_TEAPOT; Display(); break; case WIRE_OCTAHEDRON: object = WIRE_OCTAHEDRON; Display(); break; case WIRE_TETRAHEDRON: object = WIRE_TETRAHEDRON; Display(); break; case WIRE_ICOSAHEDRON: object = WIRE_ICOSAHEDRON; Display(); break; case EXIT: exit( 0 ); } }
int main( int argc, char * argv[] ) { glutInit( & argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowSize( 400, 400 ); #ifdef WIN32 glutCreateWindow( "Przekształcenia" ); #else glutCreateWindow( "Przeksztalcenia" ); #endif glutDisplayFunc( Display ); glutReshapeFunc( Reshape ); glutKeyboardFunc( Keyboard ); glutSpecialFunc( SpecialKeys ); glutMouseFunc( MouseButton ); glutMotionFunc( MouseMotion ); int MenuAspect = glutCreateMenu( Menu ); #ifdef WIN32 glutAddMenuEntry( "Aspekt obrazu - całe okno", FULL_WINDOW ); #else glutAddMenuEntry( "Aspekt obrazu - cale okno", FULL_WINDOW ); #endif glutAddMenuEntry( "Aspekt obrazu 1:1", ASPECT_1_1 ); int MenuObject = glutCreateMenu( Menu ); glutAddMenuEntry( "Kula", WIRE_SPHERE ); #ifdef WIN32 glutAddMenuEntry( "Stożek", WIRE_CONE ); glutAddMenuEntry( "Sześcian", WIRE_CUBE ); glutAddMenuEntry( "Torus", WIRE_TORUS ); glutAddMenuEntry( "Dwunastościan", WIRE_DODECAHEDRON ); glutAddMenuEntry( "Czajnik", WIRE_TEAPOT ); glutAddMenuEntry( "Ośmiościan", WIRE_OCTAHEDRON ); glutAddMenuEntry( "Czworościan", WIRE_TETRAHEDRON ); glutAddMenuEntry( "Dwudziestościan", WIRE_ICOSAHEDRON ); #else glutAddMenuEntry( "Stozek", WIRE_CONE ); glutAddMenuEntry( "Szescian", WIRE_CUBE ); glutAddMenuEntry( "Torus", WIRE_TORUS ); glutAddMenuEntry( "Dwunastoscian", WIRE_DODECAHEDRON ); glutAddMenuEntry( "Czajnik", WIRE_TEAPOT ); glutAddMenuEntry( "Osmioscian", WIRE_OCTAHEDRON ); glutAddMenuEntry( "Czworoscian", WIRE_TETRAHEDRON ); glutAddMenuEntry( "Dwudziestoscian", WIRE_ICOSAHEDRON ); #endif glutCreateMenu( Menu ); glutAddSubMenu( "Aspekt obrazu", MenuAspect ); glutAddSubMenu( "Obiekt", MenuObject ); #ifdef WIN32 glutAddMenuEntry( "Wyjście", EXIT ); #else glutAddMenuEntry( "Wyjscie", EXIT ); #endif glutAttachMenu( GLUT_RIGHT_BUTTON ); glutMainLoop(); return 0; }
|