Вот есть код... 1. Он вылетает на строчке обозначченной равенствами. если её убрать, то вылетает на строчке в таймере... 2. не могу никак придумать как сделать так чтобы шарики колебались по sin красный вверх/вниз синий и зелёный по диагонали вообщем двигались к вершинам треугольника а потом в центр...
| Код | #pragma comment (lib, "opengl32.lib") #pragma comment (lib, "glut32.lib") #pragma comment (lib, "glu32.lib") //#include "stdafx.h"
#include <windows.h>
#include <GL/glut.h> #include <GL/glext.h> #include <stdio.h> #include <math.h> #include <mmsystem.h> #include <time.h> //Тип и указатель для функции смешивающего уравнения typedef void (APIENTRY * GLBLENDEQUATION) (GLenum mode); GLBLENDEQUATION glBlendEquation=NULL;
//float sqrt(float x);
typedef struct _TVector { GLfloat x, y, z; } __TVector;
__TVector *ball_1; __TVector *ball_2; __TVector *ball_3;
float ElapsedTime; float ElapsedTime1; float vrash_sin; float vrash_cos; float FPSCount=0;
void CALLBACK TimerProc(unsigned int uID, unsigned int uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { /*float sin_travy; float cos_travy; float angle;
sin_travy = sin((ElapsedTime1/60)/1); cos_travy = cos((ElapsedTime1/60)/1); vrash_sin = 1.01 * sin_travy; vrash_cos = 1.01 * cos_travy;*/ ball_1->y = sin((ElapsedTime1/60)/1);;
}
void CALLBACK errorCallback(GLenum errorCode) { const GLubyte *estring;
estring = gluErrorString(errorCode); fprintf(stderr, "Quadric Error: %s\n", estring); exit(0); }
void init(void) { unsigned int ID; //Проверяем, присутствует ли расширение GL_ARB_imaging (imaging subset) if (glutExtensionSupported("GL_ARB_imaging")==0) { exit(1); }
//Получить указатель на функцию glBlendEquation=(GLBLENDEQUATION)wglGetProcAddress("glBlendEquation"); glClearColor(1.0, 1.0, 1.0, 1.0); timeSetEvent(2000, 0, TimerProc, 0, TIME_PERIODIC); }
void display(void) { DWORD DemoStart; DWORD LastTime; GLUquadricObj *qobj;
//DemoStart = GetTickCount(); qobj = gluNewQuadric(); gluQuadricCallback(qobj, GLU_ERROR, errorCallback);
gluQuadricDrawStyle(qobj, GLU_FILL); /* smooth shaded */
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_BLEND);
glPushMatrix(); glColor3f(0.0, 0.0, 0.0); glTranslatef(0.0, 0.707, 0.01); gluDisk(qobj, 0.05, 1.3, 30, 1); glPopMatrix();
glPushMatrix(); glColor3f(0.0, 0.0, 0.0); glTranslatef(1.0, -1.0, 0.01); gluDisk(qobj, 0.05, 1.3, 30, 1); glPopMatrix();
glPushMatrix(); glColor3f(0.0, 0.0, 0.0); glTranslatef(-1.0, -1.0, 0.01); gluDisk(qobj, 0.05, 1.3, 30, 1); glPopMatrix();
glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); glPushMatrix(); glColor3f(1.0, 0.0, 0.0); glTranslatef(0.0, 0.707 + (GLfloat)ball_1->y, 0.01);//============================ gluDisk(qobj, 0.05, 1.3, 30, 1); glPopMatrix();
glPushMatrix(); glColor3f(0.0, 1.0, 0.0); glTranslatef(1.0, -1.0, 0.01); gluDisk(qobj, 0.05, 1.3, 30, 1); glPopMatrix();
glPushMatrix(); glColor3f(0.0, 0.0, 1.0); glTranslatef(-1.0, -1.0, 0.01); gluDisk(qobj, 0.05, 1.3, 30, 1); glPopMatrix();
/*FPSCount = FPSCount + 1; LastTime = ElapsedTime; ElapsedTime = GetTickCount() - DemoStart; ElapsedTime1 = (LastTime + ElapsedTime) / 2; */ glFlush();
}
void reshape (int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); else glOrtho(-2.5*(GLfloat)w/(GLfloat)h, 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
|
Буду рад любой помощи. |