Develop
2003.04.23 10:58
[c] OpenGL 직사각형(2D) 크기 확대/축소
Views 9099 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();
}
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
841 | Develop | [ios] 아이폰용 앱 오픈 소스들 | hooni | 2013.04.23 | 470493 |
840 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 273104 |
839 | Develop | [ios] 언어, 지역, 국가 설정 가져오기 | hooni | 2014.05.12 | 272429 |
838 | Develop |
[ios] Start developing your navigation app for CarPlay without enrollment
![]() |
hooni | 2020.02.22 | 125626 |
837 | Develop |
[android] 만화 어플 소스코드
![]() |
hooni | 2013.04.23 | 92927 |
836 | Develop |
레고 마인드스톰 NXT 수도쿠, 큐브 소스코드..
20 ![]() |
hooni | 2013.04.23 | 81606 |
835 | Develop |
[c#] Hashtable <-> Json (dll 포함)
![]() |
hooni | 2013.04.23 | 80733 |
834 | Develop | [C#] MD5, SHA1 해시 & 인코딩 | hooni | 2013.04.23 | 77976 |
833 | Develop |
[android] 점심 해결 앱 소스 코드 ㅋㅋ
![]() |
hooni | 2013.04.23 | 76507 |
832 | Develop |
[json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드)
![]() |
hooni | 2013.04.23 | 72050 |
831 | Develop | [android] keytool을 사용하여 키스토어 생성 | hooni | 2013.04.23 | 69582 |
830 | Develop | [ios] Random Thoughts: Rand() vs. arc4random() | hooni | 2013.10.31 | 68128 |