IT/C,C++

[OpenGL] opengl에서 포물선그리기

미녀개발자 2018. 7. 2. 12:59
반응형


openGL 포물선 그리기








- 사용하는 변수들






이거는 움직이는 포물선 사용하려고

타이머 메소드 적다가

실패함



안움직이는 포물선 할땐 필요없음





main() 부분






- doDisplay부분


y=ax2 함수를 그리는 포물선임


거꾸로된 포물선은 a값을 -a로 바꾸면 됨


예제 코드 sample 은 아래 참고


#include <stdio.h>

#include <stdlib.h>

#include <gl/glut.h>

void DoDisplay();

const GLint width = 1200;

const GLint height = 500;

const GLfloat xSize = 0.005;

const GLfloat ySize = xSize*width / height;

GLfloat x1, x2, a=1;

GLfloat y1, y2;

const GLfloat size = 0.15;

GLfloat x1init = -1;

GLint timeInterval = 100;




void DoTimer(int value)

{

glutPostRedisplay();

glutTimerFunc(timeInterval, DoTimer, 1);

}


void main() {

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 

glutInitWindowSize(width, height);

glutCreateWindow("OpenGL");

glutDisplayFunc(DoDisplay);

glutMainLoop();

}


void DoDisplay()

{

glClear(GL_COLOR_BUFFER_BIT);


for (x1 = -1; x1 < 1; x1 += 0.001) {

y1 = -a*(x1)*(x1);

x2 = x1 + xSize;

y2 = y1 - ySize;


glRectf(x1, y1, x2, y2);

}


if (a < 1024)

a *= 2;

else

a = 1;


glutSwapBuffers();

}


반응형