По сути, я включил блок кода, который, по-видимому, компилируется и запускается, но графика не отображается в меню, которое я инициализировал. Я знаю, что код должен отображаться, потому что он компилируется, запускается и отображает то, что предполагается в Linux. Однако после переноса кода в Visual Studios и выполнения большого количества корректировок (клейкости, перенасыщенности и корректировок совместимости) он, наконец, скомпилировался, но теперь возникла другая проблема - отсутствие графики, четко отображаемой на другом компьютере. (
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include"SDL.h"
#include"SDL_opengl.h"
#include"glut.h"
#include < tchar.h >
#include < cstdlib >
#include < ctime >
#include < iostream >
#include < fstream >
#include < stdlib.h >
#include < stdio.h >
#include < string >
using namespace std;
#ifdef GL_VERSION_1_1
#define POINTER 1
#define INTERLEAVED 2
#define DRAWARRAY 1
#define ARRAYELEMENT 2
#define DRAWELEMENTS 3
int setupMethod = POINTER;
int derefMethod = DRAWARRAY;
static int legs = 0;
void setupPointers( void );
void init( void );
void display( void );
void reshape( int, int );
void keyboard( unsigned char, int, int );
int _tmain( int argc, char **argv ) {
glutInit( &argc, argv );
glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize ( 500, 500 );
glutInitWindowPosition ( 100, 100 );
glutCreateWindow ( argv[0] );
init( );
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutKeyboardFunc( keyboard );
glutMainLoop( );
return 0;
}
void setupPointers( void ) {
static GLint vertices[ ] = {
//spiderbody
-10, 35,
10, 35,
20, 55,
10, 75,
-10, 75,
-20, 55,
-10,35,
-30,25,
-30,-25,
-10,-35,
10,-35,
30,-25,
30,25,
10,35,
//legs
//leg1 position1
20,30, 40,42.5,32.5,77.5,47.5,42.5,30,25,
//leg2pos1
30,12.5,50,22.5,55,42.5,56,17.5,30,5,
//leg3pos1
30,-12.5,50,-22.5,55,-42.5,56,-17.5,30,-5,
//leg4pos1
20,-30, 40,-42.5,32.5,-77.5,47.5,-42.5,30,-25,
//leg5pos1
-20,30, -40,42.5,-32.5,77.5,-47.5,42.5,-30,25,
//leg6pos1
-30,12.5,-50,22.5,-55,42.5,-56,17.5,-30,5,
//leg7pos1
-30,-12.5,-50,-22.5,-55,-42.5,-56,-17.5,-30,-5,
//leg8pos1
-20,-30, -40,-42.5,-32.5,-77.5,-47.5,-42.5,-30,-25,
//leg1pos2
20,30,45,37.5,50,75,50,32.5,30,25,
//leg2pos2
30,12.5,51,12.5,47.5,22.5,60,5,30,5,
//leg3pos2
30,-12.5,51,-12.5,47.5,-22.5,60,-5,30,-5,
//leg4pos2
20,-30,45,-37.5,50,-75,50,-32.5,30,-25,
//leg5pos2
-20,30,-45,37.5,-50,75,-50,32.5,-30,25,
//leg6pos2
-30,12.5,-51,12.5,-47.5,22.5,-60,5,-30,5,
//leg7pos2
-30,-12.5,-51,-12.5,-47.5,-22.5,-60,-5,-30,-5,
//leg8pos2
-20,-30,-45,-37.5,-50,-75,-50,-32.5,-30,-25
};
static GLfloat colors[ ] = {
0.37, 0.35, 0.62,
0.5, 0.75, 0.25,
0.75, 0.75,0,
0.35, 0.35, 0.35,
0.5, 0.75, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
1, 0, 0,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,0.37, 0.35, 0.62,
0.5, 0.75, 0.25,
0.75, 0.75,0,
0.35, 0.35, 0.35,
0.5, 0.75, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
1, 0, 0,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,0.37, 0.35, 0.62,
0.5, 0.75, 0.25,
0.75, 0.75,0,
0.35, 0.35, 0.35,
0.5, 0.75, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
1, 0, 0,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,0.37, 0.35, 0.62,
0.5, 0.75, 0.25,
0.75, 0.75,0,
0.35, 0.35, 0.35,
0.5, 0.75, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
1, 0, 0,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,0.37, 0.35, 0.62,
0.5, 0.75, 0.25,
0.75, 0.75,0,
0.35, 0.35, 0.35,
0.5, 0.75, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
1, 0, 0,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,0.37, 0.35, 0.62,
0.5, 0.75, 0.25,
0.75, 0.75,0,
0.35, 0.35, 0.35,
0.5, 0.75, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.75,
0.75, 0.35, 0.35,
0.5, 0.28, 0.35,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.75, 0.35, 0.35,
0.5, 0.28, 0.35
}; // COLORS
glEnableClientState ( GL_VERTEX_ARRAY );
glEnableClientState ( GL_COLOR_ARRAY );
glVertexPointer ( 2, GL_INT, 0, vertices );
glColorPointer ( 3, GL_FLOAT, 0, colors );
}
void init(void) {
glColor3f( 1,1,1 );
glutWireSphere( 100,100,100 );
glShadeModel( GL_SMOOTH );
setupPointers ( );
}
void display( void ) {
glClear (GL_COLOR_BUFFER_BIT);
glDrawArrays (GL_POLYGON, 0, 14);
if( legs % 5 == 0 || legs < 5 || legs%5==1 ) {
glDrawArrays (GL_POLYGON,15,4);
glDrawArrays (GL_POLYGON,20,4);
glDrawArrays (GL_POLYGON,25,4);
glDrawArrays (GL_POLYGON,30,4);
glDrawArrays (GL_POLYGON,35,4);
glDrawArrays (GL_POLYGON,40,4);
glDrawArrays (GL_POLYGON,45,4);
glDrawArrays (GL_POLYGON,50,4);
}
//second position of legs
else if( legs % 5 !=0 && legs%5!=1 ) {
glDrawArrays (GL_POLYGON,55,4);
glDrawArrays (GL_POLYGON,60,4);
glDrawArrays (GL_POLYGON,65,4);
glDrawArrays (GL_POLYGON,70,4);
glDrawArrays (GL_POLYGON,75,4);
glDrawArrays (GL_POLYGON,80,4);
glDrawArrays (GL_POLYGON,85,4);
glDrawArrays (GL_POLYGON,90,4);
}
}
void reshape ( int w, int h ) {
glViewport ( 0, 0, (GLsizei) w, (GLsizei) h );
gluOrtho2D ( -60.0, (GLdouble) w, -60.0, (GLdouble) h );
}
void keyboard ( unsigned char key, int x, int y ) {
switch ( key ) {
case 'd':
glTranslatef( 1,1,0 );
glRotatef( -5,0,0,1.0 );
legs++;
break;
case 'a':
glTranslatef( 1,1,0 );
glRotatef( 5,0,0,1.0 );legs++;
break;
case 'w':
glTranslatef( 0,5,0 );legs++;
break;
case 's':
glTranslatef( 0,-5,0 );legs++;
break;
case 27:
exit(0);
break;
default:
break;
}
glutPostRedisplay( );
}
#else
#endif