LINUX.ORG.RU

Начал изучать openGL


0

0

Компилирую командой gcc test.c -o test -lglut
Получаю варинги и ошибки:
test.c:5: warning: built-in function ‘y1’ declared as non-function
test.c:11: warning: data definition has no type or storage class
test.c:11: error: conflicting types for ‘x1’
test.c:4: error: previous declaration of ‘x1’ was here
test.c:12: warning: data definition has no type or storage class
test.c:12: error: conflicting types for ‘y1’
test.c:5: error: previous declaration of ‘y1’ was here
test.c:13: warning: data definition has no type or storage class
test.c:13: error: conflicting types for ‘rsize’
test.c:6: error: previous declaration of ‘rsize’ was here
test.c:14: warning: data definition has no type or storage class
test.c:14: error: conflicting types for ‘xstep’
test.c:7: error: previous declaration of ‘xstep’ was here
test.c:15: warning: data definition has no type or storage class
test.c:15: error: conflicting types for ‘ystep’
test.c:8: error: previous declaration of ‘ystep’ was here

что тут не так? в гугле полазил внятного ничего ненашел

#include <GL/gl.h>
#include <GL/glut.h>

GLfloat x1;
GLfloat y1;
GLfloat rsize;
GLfloat xstep;
GLfloat ystep;
GLfloat windowWidth;
GLfloat windowHeight;
x1 = 0.0f;
y1 = 0.0f;
rsize = 25;
xstep = 1.0f;
ystep = 1.0f;
void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(x1, y1, x1+rsize, y1-rsize);
glutSwapBuffers();
}

void TimerFunction(int value){
if (x1 > windowWidth-rsize || x1 < -windowWidth)
xstep = -xstep;
if (y1 > windowHeight || y1 < -windowHeight+rsize)
ystep = -ystep;
x1 += xstep;
y1 +=ystep;
if (x1 > (windowWidth-rsize+xstep))
x1 = windowWidth - rsize - 1;
else if (x1 < -(windowWidth+xstep))
x1 = -windowWidth - 1;
if (y1 > (windowHeight+ystep))
y1 = windowHeight - 1;
else if (y1 < -(windowHeight-rsize+ystep))
y1 = -windowHeight + rsize - 1;
glutPostRedisplay();
glutTimerFunc(33,TimerFunction,1);
}

void SetupRC(void){
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}

void ChangeSize(GLsizei w, GLsizei h){
GLfloat aspectRatio;
if (h == 0) h=1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h){
windowWidth = 100;
windowHeight = 100 / aspectRatio;
glOrtho(-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
}
else{
windowWidth = 100 * aspectRatio;
windowHeight = 100;
glOrtho(-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutTimerFunc(33, TimerFunction, 1);
SetupRC();
glutMainLoop();
return 0;
}


static GLfloat x1 = 0.0f;
static GLfloat y1 = 0.0f;
static GLfloat rsize = 25;
static GLfloat xstep = 1.0f;
static GLfloat ystep = 1.0f;
static GLfloat windowWidth;
static GLfloat windowHeight;

man K&R

gcc -o test test.c -lGL -lglut -lm

CL-USER
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.