Develop
2003.04.23 10:58
[c] OpenGL 직사각형(2D) 크기 확대/축소
조회 수 9070 댓글 0
#include<stdlib.h>
#include<GL/glut.h>
GLfloat vertices[][2] = {
{-0.1, 0.1}, {-0.1, -0.1}, {0.1, -0.1}, {0.1, 0.1}
};
int R=120, G=0, B=120;
double rec_size=1;
void drawSquare(){
int i;
glColor3ub( R, G, B );
glBegin(GL_POLYGON);
for(i=0; i<4; i++) glVertex3fv(vertices[i]);
glEnd();
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(rec_size, rec_size, rec_size);
drawSquare();
glFlush();
glutSwapBuffers();
}
void mouse(int btn, int state, int x, int y){
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN && rec_size<32){
R+=20; B-=20;
rec_size *= 2;
}
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN && rec_size>0.1){
R-=20; B+=20;
rec_size /= 2;
}
glutPostRedisplay();
}
void myReshape(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0 * (GLfloat)h / (GLfloat)w, 2.0 * (GLfloat)h / (GLfloat)w, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Square!!");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
-
[c++] 인라인 함수 설명과 예제..
-
[c++] 인라인 함수에 대한 설명
-
[c++] 자료구조(링크리스트,스택,큐)와 후위 표기 계산기 샘플 ㅋㅋ
-
[c++] 중복실행 방지(Mutex;뮤텍스 ) 샘플 소스.. ㅋㅋ
-
[c++] 채팅로봇 소스.. ㅋㄷㅋㄷ
-
[c++] 초간단 스택 두 가지 방식(class, struct)
-
[c++] 템플릿(Template) 예제 소스..
-
[c++] 트리컨트롤 스텝 2 예제..
-
[c++] 트리컨트롤 스텝 3 예제..
-
[c++] 트리컨트롤 예제1 ㅋㅋ
-
[c++] 퍼즐 버블버블 간단한 원리(사용공식)
-
[c++] 프리렉(freelec) 예제 자료.. ㅋㄷ