API:OPENGL

구차니의 잡동사니 위키
이동: 둘러보기, 찾기


목차

우분투

환경구축

$ sudo apt-get install build-essential freeglut3-dev libglui-dev

빌드

$ gcc -lglut -lGLU -lGL -lm glfile.c


API

GL

GLU

GLUT

스켈레톤 코드

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

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW); //GL_PROJECTION
	glPushMatrix();
	glPopMatrix();
	glutSwapBuffers();
}

void reshape(int w, int h)
{
	glViewport(0, 0, (GLsizei) w, (GLsizei) h);
}

void keyboard(unsigned char key, int x, int y)
{
	printf("key[%d] x[%d] y[%d]\n",key,x,y);
	switch (key)
	{
		default:
		break;
	}
}

void keyboard_spe(int key, int x, int y)
{
	printf("key[%d] x[%d] y[%d]\n",key,x,y);
	switch (key)
	{
		case GLUT_KEY_F1:
		case GLUT_KEY_F2:
		case GLUT_KEY_F3:
		case GLUT_KEY_F4:
		case GLUT_KEY_F5:
		case GLUT_KEY_F6:
		case GLUT_KEY_F7:
		case GLUT_KEY_F8:
		case GLUT_KEY_F9:
		case GLUT_KEY_F10:
		case GLUT_KEY_F11:
		case GLUT_KEY_F12:
		case GLUT_KEY_LEFT:
		case GLUT_KEY_RIGHT:
		case GLUT_KEY_UP:
		case GLUT_KEY_DOWN:
		case GLUT_KEY_PAGE_UP:
		case GLUT_KEY_PAGE_DOWN:
		case GLUT_KEY_HOME:
		case GLUT_KEY_END:
		case GLUT_KEY_INSERT:
		default:
			break;
	}
}

void mouse(int button, int state, int x, int y)
{
	printf("button[%d] state[%d] x[%d] y[%d]\n",button,state,x,y);
	switch(button)
	{
		case GLUT_LEFT_BUTTON:
		case GLUT_MIDDLE_BUTTON:
		case GLUT_RIGHT_BUTTON:
	}

	switch(state)
	{
		case GLUT_UP:
		case GLUT_DOWN:
	}
}

void mouse_motion(int x, int y)
{
	printf("motion x[%d] y[%d]\n",x,y);
}

void mouse_passive(int x, int y)
{
	printf("passive x[%d] y[%d]\n",x,y);
}

void idlefunc()
{
	glutPostRedisplay();
}

void timerfunc(int value)
{
	glutTimerFunc(1000, timerfunc, 0);
}

void entry(int state)
{
	printf("entry state[%d]\n",state);
	switch(state)
	{
		case GLUT_LEFT:
		case GLUT_ENTERED:
			break;
	}
}

void visibility(int state)
{
	printf("visibility state[%d]\n",state);
	switch(state)
	{
		case GLUT_NOT_VISIBLE:
		case GLUT_VISIBLE:
			break;
	}
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

	// GLUT Window
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	glutCreateWindow(argv[0]);

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_FLAT); //GL_SMOOTH

	glutDisplayFunc(display);				// Draw callback
	glutReshapeFunc(reshape);				// Draw callback - windwow resize
	glutKeyboardFunc(keyboard);				// Keyboard callback
	glutSpecialFunc(keyboard_spe);			// Keyboard callback
	glutMouseFunc(mouse);					// Mouse callback
	glutMotionFunc(mouse_motion);			// Mouse callback
	glutPassiveMotionFunc(mouse_passive);	// Mouse callback
	glutIdleFunc(idlefunc);					// Period callback
	glutTimerFunc(1000, timerfunc, 0);		// Period callback
	glutEntryFunc(entry);					// Window callback
	glutVisibilityFunc(visibility);			// Window callback

	glutMainLoop();
	return 0;
}
개인 도구
이름공간

변수
행위
둘러보기
도구모음