Develop
2003.04.23 10:58
[c] OpenGL 직사각형(2D) 크기 확대/축소
Views 9098 Comment 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] OpenGL 임시로 여기 올림..
-
[c] OpenGL 직사각형(2D) 크기 확대/축소
-
[c] openssl 샘플코드.. 어려움 ㅠㅠ
-
[c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ
-
[c] pcap을 이용한 패킷 분석 ㅎㅎ
-
[c] RSA 암호화 구현(gmp 라이브러리 활용)
-
[c] scanf(), printf() 포맷의 형변환
-
[c] selec()를 이용한 입출력 다중화
-
[c] SetTimer() & KillTimer() & 일회용 Timer
-
[c] UCP/TCP 채팅 소스 - 정리해야 함..
-
[c] Unix Domain Socket 을 이용한 IPC
-
[c] UTF-8을 EUC-KR로 변환.. (iconv)