Доброго всем времени суток. Есть такая проблема. Написал приложение OpenGL, ящик съезжает по наклонной плоскости. Но при анимации заметны подлагивания, т.е. на глаз видно что ящик съезжает не плавно равнозамедленно а рывками. Как исправить сию проблему? Код (Text): #include "stdafx.h" #include "windows.h" #include <math.h> #include <glut.h> #include <glext.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <lib3ds.h> #include <lib3ds_impl.h> #pragma comment(lib, "lib3ds.lib") #include <Vector3D.h> #include <Vector2D.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> #pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking #pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking #pragma comment(lib, "glaux.lib") Lib3dsMesh *testmesh; float GLTrivert[0xFFFF][3]; float GLTrinorm[0xFFFF][3]; PFNGLACTIVETEXTUREARBPROC glActiveTextureARB = NULL; FILE* hFile; Vector3D eye ( 2, 2, 2 ); // camera position Vector3D light ( 0.5, 0, 1 ); // light position unsigned normCubeMap; // normalization cubemap id unsigned bumpMap; // normal map unsigned decalMap; // decal (diffuse) texture float angle = 0; Vector3D v [4]; Vector2D t0 [4]; Vector3D t1 [4]; GLfloat rtri; // Oaie aey ie?aieau GLfloat rquad; // Oaie aey eaaa?aoa int nfaces_wedge, nfaces_box; int nfaces_vector_1_1, nfaces_vector_1_2, nfaces_vector_2_1, nfaces_vector_2_2; int nfaces_vector_3_1, nfaces_vector_3_2, nfaces_vector_4_1, nfaces_vector_4_2; float (*vertex_normal_wedge)[3]; float (*vertex_normal_box)[3]; float (*face_normal_wedge)[3]; float (*face_normal_box)[3]; float (*vertex_normal_vector_1_1)[3]; float (*face_normal_vector_1_1)[3]; float (*vertex_normal_vector_1_2)[3]; float (*face_normal_vector_1_2)[3]; float (*vertex_normal_vector_2_1)[3]; float (*face_normal_vector_2_1)[3]; float (*vertex_normal_vector_2_2)[3]; float (*face_normal_vector_2_2)[3]; float (*vertex_normal_vector_3_1)[3]; float (*face_normal_vector_3_1)[3]; float (*vertex_normal_vector_3_2)[3]; float (*face_normal_vector_3_2)[3]; float (*vertex_normal_vector_4_1)[3]; float (*face_normal_vector_4_1)[3]; float (*vertex_normal_vector_4_2)[3]; float (*face_normal_vector_4_2)[3]; Lib3dsFile *Model_1,*Model_2, *Model_3, *Model_4, *Model_5, *Model_6, *Model_7, *Model_8, *Model_9, *Model_10; //Lib3dsIo *testio; char TexName [1024]; char exten [0xFFFF]; unsigned texture1; GLuint base; GLfloat cnt1; GLfloat cnt2; HDC hDC=NULL; HWND hWnd; GLYPHMETRICSFLOAT gmf[256]; // Storage For Information About Our Outline Font Characters GLuint textures[2]; float Scale_X, Scale_Y, Scale_Z; unsigned int wedge_tex, box_tex; struct S_N3F_V3F { float vertex_normal [3]; float vertices [3]; }; struct S_T2F_N3F_V3F { float TexCoord [2]; float vertex_normal [3]; float vertices [3]; }; S_T2F_N3F_V3F *Model_1_array, *Model_2_array; S_N3F_V3F *Model_3_array, *Model_4_array, *Model_5_array, *Model_6_array, *Model_7_array, *Model_8_array, *Model_9_array, *Model_10_array; Vector3D box_vector ( -1.0, 0.0, 0 ); Vector3D box_coord ( 0, 0, 0 ); Vector3D Translate (0.0f,-10.0f,-30.0f); Vector3D mg_vector ( -0.9527, -0.304, 0 ); //Преременные времени unsigned msec = 0; unsigned old_msec = 0; unsigned StartTime; float T, S, old_S, F_1; bool start_animation = FALSE; bool rotate = FALSE; bool transparency = FALSE; float alpha, alpha_r, h, h_default, hc, g; float F_module, Ft_module, N_module, Ff_module, CoeffFriction, InitialSpeed; void Load3Ds(const char *Filename, Lib3dsFile **Model_X, float (**vertex_normal)[3], float (**face_normal)[3], int *nfaces) { *Model_X = lib3ds_file_open(Filename); *vertex_normal = (float (*)[3])malloc(sizeof(float) * 9 * (*Model_X)->meshes[0]->nfaces); *face_normal = (float (*)[3])malloc(sizeof(float) * 3 * (*Model_X)->meshes[0]->nfaces); lib3ds_mesh_calculate_vertex_normals((*Model_X)->meshes[0], (float (*)[3])*vertex_normal); lib3ds_mesh_calculate_face_normals((*Model_X)->meshes[0], (float (*)[3])*face_normal); *nfaces = (*Model_X)->meshes[0]->nfaces; } void init () { alpha_r = alpha*3.14159265f/180.0f; mg_vector.y = -1.0f*sin(alpha_r); mg_vector.x = -1.0f*cos(alpha_r); Ft_module = 4.716f; F_module = Ft_module * sin(alpha_r); N_module = Ft_module * cos(alpha_r); Ff_module = CoeffFriction * N_module; h=30.005f * tan(alpha_r); h_default =30.005f * tan(17.73323859f*3.14159265f/180.0f); hc = 26.90f * tan(alpha_r) + 1.647f; F_1 = 1; Scale_X = 1.0; Load3Ds("vector_1_1.3ds", &Model_3, &vertex_normal_vector_1_1, &face_normal_vector_1_1, &nfaces_vector_1_1); Load3Ds("vector_1_2.3ds", &Model_4, &vertex_normal_vector_1_2, &face_normal_vector_1_2, &nfaces_vector_1_2); Load3Ds("vector_2_1.3ds", &Model_5, &vertex_normal_vector_2_1, &face_normal_vector_2_1, &nfaces_vector_2_1); Load3Ds("vector_2_2.3ds", &Model_6, &vertex_normal_vector_2_2, &face_normal_vector_2_2, &nfaces_vector_2_2); Load3Ds("vector_3_1.3ds", &Model_7, &vertex_normal_vector_3_1, &face_normal_vector_3_1, &nfaces_vector_3_1); Load3Ds("vector_3_2.3ds", &Model_8, &vertex_normal_vector_3_2, &face_normal_vector_3_2, &nfaces_vector_3_2); Load3Ds("vector_4_1.3ds", &Model_9, &vertex_normal_vector_4_1, &face_normal_vector_4_1, &nfaces_vector_4_1); Load3Ds("vector_4_2.3ds", &Model_10, &vertex_normal_vector_4_2, &face_normal_vector_4_2, &nfaces_vector_4_2); Load3Ds("wedge.3ds", &Model_1, &vertex_normal_wedge, &face_normal_wedge, &nfaces_wedge); printf("Load Texture - %s\n",Model_1->materials[0]->texture1_map.name); AUX_RGBImageRec *texture1; texture1 = auxDIBImageLoadA(Model_1->materials[0]->texture1_map.name); Load3Ds("box.3ds", &Model_2, &vertex_normal_box, &face_normal_box, &nfaces_box); printf("Load Texture - %s\n",Model_2->materials[0]->texture1_map.name); AUX_RGBImageRec *texture2; texture2 = auxDIBImageLoadA(Model_2->materials[0]->texture1_map.name); glGenTextures(1, &wedge_tex); glGenTextures(1, &box_tex); glClearColor ( 0, 0, 0, 1 ); glEnable ( GL_DEPTH_TEST ); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glDepthFunc ( GL_LEQUAL ); glHint ( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); glHint ( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); glBindTexture(GL_TEXTURE_2D,wedge_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,box_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, texture2->sizeX, texture2->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture2->data); glEnable(GL_TEXTURE_2D); hWnd = FindWindowA("GLUT", "Visual Source V1.0.0"); hDC=GetWindowDC(hWnd); // BuildFont(); HFONT font; // Windows Font ID base = glGenLists(256); // Storage For 256 Characters font = CreateFont( -12, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch NULL); // Font Name SelectObject(hDC, font); // Selects The Font We Created wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.0f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); // Address Of Buffer To Recieve Data } GLvoid glPrint(float x, float y, float z, const char *fmt, ...) // Custom GL "Print" Routine { float length=0; // Used To Find The Length Of The Text char text[256]; // Holds Our String va_list ap; // Pointer To List Of Arguments if (fmt == NULL) // If There's No Text return; // Do Nothing va_start(ap, fmt); // Parses The String For Variables vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers va_end(ap); // Results Are Stored In Text for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length { length+=gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width } glTranslatef(x - length, y, z); // Position Text On The Screen glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits glListBase(base); // Sets The Base Character to 0 glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); // Pops The Display List Bits glTranslatef(-x, -y, -z); // Position Text On The Screen } void display () { } void reshape ( int w, int h ) { glViewport ( 0, 0, (GLsizei)w, (GLsizei)h ); glMatrixMode ( GL_PROJECTION ); glLoadIdentity (); gluPerspective ( 60.0, (GLfloat)w/(GLfloat)h, 1.0, 60.0 ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity (); gluLookAt ( eye.x, eye.y, eye.z, // eye 0, 0, 0, // center 0.0, 0.0, 1.0 ); // up } void key ( unsigned char key, int x, int y ) { if ( key == 27 || key == 'q' || key == 'Q' ) // quit requested exit ( 0 ); if ( key == 'w' ) // quit requested rtri+=1.2f; if ( key == 0x0D ) // quit requested { start_animation = TRUE; StartTime = (unsigned)GetTickCount(); } if ( key == 'r' ) // quit requested { start_animation = TRUE; old_S = 0.0; } if ( key == 'e' ) // quit requested { if (rotate == FALSE) rotate = TRUE; else rotate = FALSE; } if ( key == 't' ) // quit requested { if (transparency == FALSE) transparency = TRUE; else transparency = FALSE; } } void animate () { msec = (unsigned)GetTickCount(); if (old_msec == msec) return; old_msec = msec; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Na?in i?iniio?a glTranslatef(Translate.x, Translate.y, Translate.z); // Naaea aeaai e aaeoau ye?aia glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRotatef(rtri,0.0f,1.0f,0.0f); // A?auaiea ie?aieau ii ine Y //************************************************** //Анимация ящика //************************************************** if (start_animation == TRUE) { T = (msec - StartTime) / 1000.0f; //вычислим время анимации S = (InitialSpeed*T - (g*T*T/2.0f) * (CoeffFriction * cos(alpha_r) - sin(alpha_r))); //Вычислим путь F_1 = -2.0f*((S*(-1.0f)) - InitialSpeed*T)/(T*T); if (old_S > S) { S = old_S; F_1 = 1.0f; } old_S = S; } //************************************************** //************************************************** //PUSH 1 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); //if (F_1 != 1.0f) //printf("S=%f, T=%f, F=%f\n", S, T, F_1); glTranslatef(11.0f, hc, 0.0); if (start_animation == TRUE) { box_coord = mg_vector * S; glTranslatef(box_coord.x, box_coord.y, box_coord.z); } //************************************************** //PUSH 4 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRotatef(alpha,0.0f,0.0f,1.0f); //************************************************** //PUSH 2 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(Ft_module - F_module , 0.0f, 0.0f); glTranslatef((-F_1 * F_module) + F_module, 0.0f, 0.0f); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_1_1; i++){ glColor3f(1.0f,1.0f,0.0f); glNormal3fv(face_normal_vector_1_1[i]); glNormal3fv(vertex_normal_vector_1_1[i*3]); glVertex3fv(Model_3->meshes[0]->vertices[Model_3->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_1_1[i*3+1]); glVertex3fv(Model_3->meshes[0]->vertices[Model_3->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_1_1[i*3+2]); glVertex3fv(Model_3->meshes[0]->vertices[Model_3->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 2 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); //************************************************** //PUSH 3 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(F_1*(F_module/Ft_module),1,1); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_1_2; i++){ glColor3f(0.0f,1.0f,0.0f); glNormal3fv(face_normal_vector_1_2[i]); glNormal3fv(vertex_normal_vector_1_2[i*3]); glVertex3fv(Model_4->meshes[0]->vertices[Model_4->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_1_2[i*3+1]); glVertex3fv(Model_4->meshes[0]->vertices[Model_4->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_1_2[i*3+2]); glVertex3fv(Model_4->meshes[0]->vertices[Model_4->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 3 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); //************************************************** //PUSH 5 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(0.0f, N_module-Ft_module, 0.0f); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_2_1; i++){ glColor3f(0.0f,0.0f,1.0f); glNormal3fv(face_normal_vector_2_1[i]); glNormal3fv(vertex_normal_vector_2_1[i*3]); glVertex3fv(Model_5->meshes[0]->vertices[Model_5->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_2_1[i*3+1]); glVertex3fv(Model_5->meshes[0]->vertices[Model_5->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_2_1[i*3+2]); glVertex3fv(Model_5->meshes[0]->vertices[Model_5->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 5 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); //************************************************** //PUSH 6 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(1,N_module/Ft_module,1); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_2_2; i++){ glColor3f(0.0f,1.0f,0.0f); glNormal3fv(face_normal_vector_2_2[i]); glNormal3fv(vertex_normal_vector_2_2[i*3]); glVertex3fv(Model_6->meshes[0]->vertices[Model_6->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_2_2[i*3+1]); glVertex3fv(Model_6->meshes[0]->vertices[Model_6->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_2_2[i*3+2]); glVertex3fv(Model_6->meshes[0]->vertices[Model_6->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 6 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); //************************************************** //PUSH 7 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(Ff_module-Ft_module, 0.0f, 0.0f); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_3_1; i++){ glColor3f(1.0f,0.0f,0.0f); glNormal3fv(face_normal_vector_3_1[i]); glNormal3fv(vertex_normal_vector_3_1[i*3]); glVertex3fv(Model_7->meshes[0]->vertices[Model_7->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_3_1[i*3+1]); glVertex3fv(Model_7->meshes[0]->vertices[Model_7->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_3_1[i*3+2]); glVertex3fv(Model_7->meshes[0]->vertices[Model_7->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 7 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); //************************************************** //PUSH 8 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(Ff_module/Ft_module,1.0f,1.0f); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_3_2; i++){ glColor3f(0.0f,1.0f,0.0f); glNormal3fv(face_normal_vector_3_2[i]); glNormal3fv(vertex_normal_vector_3_2[i*3]); glVertex3fv(Model_8->meshes[0]->vertices[Model_8->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_3_2[i*3+1]); glVertex3fv(Model_8->meshes[0]->vertices[Model_8->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_3_2[i*3+2]); glVertex3fv(Model_8->meshes[0]->vertices[Model_8->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 8 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); //************************************************** //POP 4 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_4_1; i++){ glColor3f(0.5f,0.0f,1.0f); glNormal3fv(face_normal_vector_4_1[i]); glNormal3fv(vertex_normal_vector_4_1[i*3]); glVertex3fv(Model_9->meshes[0]->vertices[Model_9->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_4_1[i*3+1]); glVertex3fv(Model_9->meshes[0]->vertices[Model_9->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_4_1[i*3+2]); glVertex3fv(Model_9->meshes[0]->vertices[Model_9->meshes[0]->faces[i].index[2]]); } glEnd(); glBegin(GL_TRIANGLES); for(int i=0; i<nfaces_vector_4_2; i++){ glColor3f(0.0f,1.0f,0.0f); glNormal3fv(face_normal_vector_4_2[i]); glNormal3fv(vertex_normal_vector_4_2[i*3]); glVertex3fv(Model_10->meshes[0]->vertices[Model_10->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_vector_4_2[i*3+1]); glVertex3fv(Model_10->meshes[0]->vertices[Model_10->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_vector_4_2[i*3+2]); glVertex3fv(Model_10->meshes[0]->vertices[Model_10->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 1 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); if (transparency == TRUE) { glEnable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } //************************************************** //POP 9 //************************************************** glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(1.0f, h/h_default, 1.0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, wedge_tex); glBegin(GL_TRIANGLES); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_REPLACE); //Возможные значения: GL_MODULATE GL_BLEND GL_REPLACE for(int i=0; i<nfaces_wedge; i++){ glColor4f(1.0f,1.0f,1.0f, 0.5f); glNormal3fv(face_normal_wedge[i]); glNormal3fv(vertex_normal_wedge[i*3]); glTexCoord2fv(Model_1->meshes[0]->texcos[Model_1->meshes[0]->faces[i].index[0]]); glVertex3fv(Model_1->meshes[0]->vertices[Model_1->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_wedge[i*3+1]); glTexCoord2fv(Model_1->meshes[0]->texcos[Model_1->meshes[0]->faces[i].index[1]]); glVertex3fv(Model_1->meshes[0]->vertices[Model_1->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_wedge[i*3+2]); glTexCoord2fv(Model_1->meshes[0]->texcos[Model_1->meshes[0]->faces[i].index[2]]); glVertex3fv(Model_1->meshes[0]->vertices[Model_1->meshes[0]->faces[i].index[2]]); } glEnd(); //************************************************** //POP 9 //************************************************** glMatrixMode(GL_MODELVIEW); glPopMatrix(); glTranslatef(11.0f, hc, 0.0f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRotatef(alpha,0.0f,0.0f,1.0f); //************************************************** //Анимация ящика //************************************************** if (start_animation == TRUE) { box_coord = box_vector * S; glTranslatef(box_coord.x, box_coord.y, box_coord.z); } //************************************************** glBindTexture(GL_TEXTURE_2D, box_tex); glBegin(GL_TRIANGLES); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_REPLACE); //Возможные значения: GL_MODULATE GL_BLEND GL_REPLACE for(int i=0; i<nfaces_box; i++){ glColor4f(1.0f,1.0f,1.0f, 0.5f); glNormal3fv(face_normal_box[i]); glNormal3fv(vertex_normal_box[i*3]); glTexCoord2fv(Model_2->meshes[0]->texcos[Model_2->meshes[0]->faces[i].index[0]]); glVertex3fv(Model_2->meshes[0]->vertices[Model_2->meshes[0]->faces[i].index[0]]); glNormal3fv(vertex_normal_box[i*3+1]); glTexCoord2fv(Model_2->meshes[0]->texcos[Model_2->meshes[0]->faces[i].index[1]]); glVertex3fv(Model_2->meshes[0]->vertices[Model_2->meshes[0]->faces[i].index[1]]); glNormal3fv(vertex_normal_box[i*3+2]); glTexCoord2fv(Model_2->meshes[0]->texcos[Model_2->meshes[0]->faces[i].index[2]]); glVertex3fv(Model_2->meshes[0]->vertices[Model_2->meshes[0]->faces[i].index[2]]); } glEnd(); glDisable(GL_TEXTURE_2D); if (transparency == TRUE) { glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); } glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glutSwapBuffers (); if (rotate == TRUE) rtri+=0.2f; } void printExtList ( const char * extension ) { char name [1024]; // hope this will be enough int i, j, k; k=0; k = k + sprintf(exten + k, "\nSupported extensions:\n"); printf ( "Supported extensions:\n" ); for ( i = 0, j = 0; extension [i] != '\0'; i++ ) if ( !isspace ( extension [i] ) ) name [j++] = extension [i]; else // end of name { name [j] = '\0'; // terminate name printf ( "\t%s\n", name ); k = k + sprintf(exten + k, "%s\n", name); j = 0; } if ( j > 0 ) { name [j] = '\0'; printf ( "\t%s\n", name ); k = k + sprintf(exten + k, "%s\n", name); } } int main (int argc, char **argv) { g = 9.8f; alpha = 17.73323859f; CoeffFriction = 0.68f; InitialSpeed = 15.0f; if (argc >= 2) { g = atof(argv [1]); printf("g = %f\n",g); } if (argc >= 3) { alpha = atof(argv [2]); printf("alpha = %f\n",alpha); } if (argc >= 4) { CoeffFriction = atof(argv [3]); printf("CoeffFriction = %f\n",CoeffFriction); } if (argc >= 5) { InitialSpeed = atof(argv [4]); printf("InitialSpeed = %f\n",InitialSpeed); } printf("%d\n",LoadLibrary(TEXT("lib3ds-2_0.dll"))); printf("%d\n",GetLastError()); // initialize glut glutInit ( &argc, argv ); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize ( 1024, 786 ); //printf("\n%d\n", LoadLibrary(TEXT("opengl32.dll"))); //glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) GetProcAddress(GetModuleHandle(TEXT("opengl32.dll")), "glActiveTextureARB"); // if (glActiveTextureARB==0) { // MessageBoxA(0, "glActiveTextureARB=0", "glActiveTextureARB", MB_ICONERROR); // printf("\n%d\n", GetLastError()); //} // create window int Wnd = glutCreateWindow ( "Visual Source V1.0.0" ); // register handlers glutDisplayFunc ( display ); glutReshapeFunc ( reshape ); glutKeyboardFunc ( key ); glutIdleFunc ( animate ); init (); // setup vertices //Lib3dsFile *file = lib3ds_file_open("box.3ds"); //lib3ds_file_free(file); const char * vendor = (const char *)glGetString ( GL_VENDOR ); const char * renderer = (const char *)glGetString ( GL_RENDERER ); const char * version = (const char *)glGetString ( GL_VERSION ); const char * extension = (const char *)glGetString ( GL_EXTENSIONS ); char buffer [1024]; sprintf(buffer, "Vendor: %s\nRenderer: %s\nVersion: %s\n", vendor, renderer, version); hFile = fopen("GL.log", "w"); fwrite(buffer, 1, strlen(buffer), hFile); ; printf ( "Vendor: %s\nRenderer: %s\nVersion: %s\n", vendor, renderer, version ); printExtList ( extension ); fwrite(exten, 1, strlen(exten), hFile); fclose(hFile); glutMainLoop (); return 0; } Вот проект целиком 10 Метров http://31.31.203.47/OpenGL_X.zip
У меня были рывки объектов в игре из-за того, что отрисовка идет в одном потоке, а изменение координат рисуемых объектов в другом потоке. Помогла синхронизация данных. Правда у меня java. У тебя как я понял все в одном потоке (в сях не шарю, грешен). Правильно будет выделить для изменения координат и других параметров, зависимых от времени, отдельный поток, то есть отрисовка отдельно, логика отдельно.
Ну я об этом думал, хотя вот в уроке NEHE http://pmg.org.ru/nehe/nehe30.htm вычислений больше но лагов то нет как и многопоточности... Походу чтото в самой реализации...
Все разобрался, частоты кадровой развертки маленькая была, дров криво поставлен и не настроена OpenGL. Буду ковырять API настройки OpenGL.