Mam swój projekt OGL w ktorym nie moge narysować siatki i nie wiem właściwie czemu. Może mógłby mi ktoś pomóc
#include <stdlib.h>
#include <GL/glut.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 siatka()
{
GLfloat x, y, z, angle;
GLint i, j;
glBegin( GL_LINES );
z = 0.0f;
y = 0.0f;
glColor3f( 0.2f, 0.8f, 0.0f );
for( i =- 100; i < 100; i = i + 2 )
{
glVertex3f( - 100.0f, y, i );
glVertex3f( 100.0f, y, i );
}
for( j =- 100; j < 100; j = j + 2 )
{
glVertex3f( j, y, - 100.0f );
glVertex3f( j, y, 100.0f );
}
glEnd();
}
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 );
glScalef( scale, scale, scale );
glRotatef( rotatex, 1.0, 0, 0 );
glRotatef( rotatey, 0, 1.0, 0 );
GLfloat sa[ 3 ] = { 0.0f, 0.0f, 0.0f };
GLfloat sb[ 3 ] = { 1.0f, 0.0f, 0.0f };
GLfloat sc[ 3 ] = { 1.0f, 4.0f, 0.0f };
GLfloat sd[ 3 ] = { 0.0f, 4.0f, 0.0f };
GLfloat se[ 3 ] = { 0.0f, 0.0f, - 1.0f };
GLfloat sf[ 3 ] = { 1.0f, 0.0f, - 1.0f };
GLfloat sg[ 3 ] = { 1.0f, 4.0f, - 1.0f };
GLfloat sh[ 3 ] = { 0.0f, 4.0f, - 1.0f };
glColor3f( 1.0f, 0.0f, 0.0f );
glBegin( GL_POLYGON );
glVertex3fv( sa );
glVertex3fv( sb );
glVertex3fv( sc );
glVertex3fv( sd );
glEnd();
glColor3f( 0.0f, 1.0f, 0.0f );
glBegin( GL_POLYGON );
glVertex3fv( sb );
glVertex3fv( sf );
glVertex3fv( sg );
glVertex3fv( sc );
glEnd();
glColor3f( 0.0f, 0.0f, 1.0f );
glBegin( GL_POLYGON );
glVertex3fv( sf );
glVertex3fv( se );
glVertex3fv( sh );
glVertex3fv( sg );
glEnd();
glColor3f( 1.0f, 1.0f, 0.0f );
glBegin( GL_POLYGON );
glVertex3fv( se );
glVertex3fv( sa );
glVertex3fv( sd );
glVertex3fv( sh );
glEnd();
glColor3f( 0.0f, 1.0f, 1.0f );
glBegin( GL_POLYGON );
glVertex3fv( sd );
glVertex3fv( sc );
glVertex3fv( sg );
glVertex3fv( sh );
glEnd();
glColor3f( 1.0f, 0.0f, 1.0f );
glBegin( GL_POLYGON );
glVertex3fv( sa );
glVertex3fv( sb );
glVertex3fv( sf );
glVertex3fv( se );
glEnd();
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 -= 5;
break;
case GLUT_KEY_UP:
rotatex -= 5;
break;
case GLUT_KEY_RIGHT:
rotatey += 5;
break;
case GLUT_KEY_DOWN:
rotatex += 5;
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 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 EXIT:
exit( 0 );
}
}
int main( int argc, char * argv[] )
{
glutInit( & argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
glutInitWindowSize( 600, 600 );
#ifdef WIN32
glutCreateWindow( "Przekształcenia" );
#else
glutCreateWindow( "Przeksztalcenia" );
#endif
glutDisplayFunc( Display );
glutDisplayFunc( siatka );
glutReshapeFunc( Reshape );
glutKeyboardFunc( Keyboard );
glutSpecialFunc( SpecialKeys );
glutMouseFunc( MouseButton );
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 );
glutCreateMenu( Menu );
glutAddSubMenu( "Aspekt obrazu", MenuAspect );
#ifdef WIN32
glutAddMenuEntry( "Wyjście", EXIT );
#else
glutAddMenuEntry( "Wyjscie", EXIT );
#endif
glutAttachMenu( GLUT_RIGHT_BUTTON );
glutMainLoop();
return 0;
}