Skip to main content
Search
Search This Blog
Leegoonz game Developer blog.
Visual strategy development lab Technical Art Director. Now working atAllegorithmic.
페이지
Home
About Leegoonz
LEEGOONZ.COM
ADVANCED SHADER DOT COM
ADVANCED SHADER FACEBOOK COMMUNITY
Substance user group in korea
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
Labels
programming
May 15, 2013
GLSL CUSTOM VIEW JP FRAMEWORK.
하나씩 하나씩... 쌓아 가기...
OPEN GL.
/* *Author from JP.Lee *Ver. 0.1b *This is first OpenGL Shader preview framwork via freeglut api. *5/7/2013 first update. */ #include
#include
#include
#define GLUT_KEY_ESCAPE 27 const GLsizei windowWidth = 1280; const GLsizei windowHeight = 720; GLfloat viewFOVY = 45.0f; GLfloat cubePositionZ = -5.0f; GLfloat cubeRotateX = 45.0f; GLfloat cubeRotateY = 45.0f; bool keys[255]; const char* myTitle = "JP OpenGL VIEWER"; GLboolean checkKeys(GLvoid) { const GLfloat speed = 1.0f; const GLfloat zoom = 1.0f; const GLfloat sensitive = 5.0f; if ( keys[ GLUT_KEY_ESCAPE ]) return true; if ( keys[GLUT_KEY_LEFT]) cubeRotateY -= speed; if(keys[GLUT_KEY_RIGHT]) cubeRotateY += speed; if(keys[GLUT_KEY_UP]) cubeRotateX -= speed; if(keys[GLUT_KEY_DOWN]) cubeRotateX += speed; if(keys[GLUT_KEY_HOME]) cubePositionZ -= zoom/sensitive; if(keys[GLUT_KEY_END]) cubePositionZ += zoom/sensitive; return false; } /***********Camera zoom for mouse wheel********************* GLvoid MouseWheel(int wheel, int direction, int x, int y) { const GLfloat zoomSensitive = 100.0f; //APPLY value to camera zoom sensitive. if (direction > 0) { cameraDIst -= zoomSensitive; } else { cameraDIst += zoomSensitive; } return; } **********************************************************/ GLvoid establisheProjectionMatrix(GLsizei width, GLsizei height) { glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //first setting up make perspective view. //*************FOV gluPerspective((GLfloat)viewFOVY , (GLfloat)width / (GLfloat)height, 0.1f , 200.0f); } GLvoid initGL(GLsizei width , GLsizei height) { establisheProjectionMatrix(width , height); glShadeModel(GL_SMOOTH); glClearColor(0.0f , 0.0f , 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST); glEnable(GL_PERSPECTIVE_CORRECTION_HINT); } GLvoid displayFPS(GLvoid) { static long lastTime = glutGet (GLUT_ELAPSED_TIME); static long loops = 0; static GLfloat fps = 0.0f; int newTime = glutGet(GLUT_ELAPSED_TIME); if (newTime - lastTime > 100) { float newFPS = (float)loops / float(newTime-lastTime)* 1000.0f; fps = (fps+ newFPS) / 2.0f; char title[80]; sprintf_s(title, "JP OpenGL VIEWER - %f" , fps); glutSetWindowTitle(title); lastTime = newTime; loops = 0; } loops++; } GLvoid drawScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glTranslatef(0 , 0 , -5.0f); //offset to -z 5.0 glTranslatef(0,0,cubePositionZ); glRotatef(cubeRotateX , 1 , 0 , 0); //45 degree rotation X glRotatef(cubeRotateY , 0 , 1 , 0); //45 degree rotation +Y //큐브 그리기 glBegin(GL_QUADS); //top face glColor3f(1.0f , 0.5f , 0.0f); glVertex3f( 1.0f , 1.0f ,-1.0f); glVertex3f(-1.0f , 1.0f ,-1.0f); glVertex3f(-1.0f , 1.0f , 1.0f); glVertex3f( 1.0f , 1.0f , 1.0f); //bottom face glColor3f(0.0f , 1.0f , 0.0f); glVertex3f( 1.0f ,-1.0f ,-1.0f); glVertex3f(-1.0f ,-1.0f ,-1.0f); glVertex3f(-1.0f ,-1.0f , 1.0f); glVertex3f( 1.0f ,-1.0f , 1.0f); //front face glColor3f(1.0f , 0.0f , 0.0f); glVertex3f( 1.0f , 1.0f , 1.0f); glVertex3f(-1.0f , 1.0f , 1.0f); glVertex3f(-1.0f ,-1.0f , 1.0f); glVertex3f( 1.0f ,-1.0f , 1.0f); //back face glColor3f(1.0f , 1.0f , 0.0f);//yellow glVertex3f( 1.0f , 1.0f ,-1.0f); glVertex3f(-1.0f , 1.0f ,-1.0f); glVertex3f(-1.0f ,-1.0f ,-1.0f); glVertex3f( 1.0f ,-1.0f ,-1.0f); //left face glColor3f(0.0f , 0.0f , 1.0f);//red glVertex3f(-1.0f , 1.0f , 1.0f); glVertex3f(-1.0f , 1.0f ,-1.0f); glVertex3f(-1.0f ,-1.0f ,-1.0f); glVertex3f(-1.0f ,-1.0f , 1.0f); //right face glColor3f(1.0f , 0.0f , 1.0f); glVertex3f( 1.0f , 1.0f , 1.0f); glVertex3f( 1.0f , 1.0f ,-1.0f); glVertex3f( 1.0f ,-1.0f ,-1.0f); glVertex3f( 1.0f ,-1.0f , 1.0f); glEnd(); glFlush(); glutSwapBuffers(); displayFPS(); } GLvoid timerLoop(int value) { if ( checkKeys() ) exit(0); glutPostRedisplay(); glutTimerFunc(1 , timerLoop , 0); } GLvoid keyboardCB(unsigned char key, int x , int y) { keys[key] = true; } GLvoid keyboardUpCB(unsigned char key, int x , int y) { keys[key] = false; } GLvoid keyboardSpecialCB(int key, int x , int y) { keys[key] = true; } GLvoid keyboardSpecialUpUpCB(int key, int x , int y) { keys[key] = false; } int main ( int argc , char *argv[]) { //glut init glutInit (&argc , argv); glutInitDisplayMode(GLUT_DOUBLE); int windowID = glutCreateWindow(myTitle); glutReshapeWindow(windowWidth , windowHeight); initGL(windowWidth , windowHeight); glutDisplayFunc( drawScene ); glutKeyboardFunc( keyboardCB ); glutKeyboardUpFunc( keyboardUpCB ); glutSpecialFunc( keyboardSpecialCB ); glutSpecialUpFunc( keyboardSpecialUpUpCB ); //this line is behavior after will make glCamera. // glutMouseWheelFunc( MouseWheel ); glutTimerFunc(1,timerLoop,0); glutMainLoop(); return 0; }
Game Developer Leegoon copyright all right reserved since 2010.
Comments
Popular Posts
December 30, 2011
구조체 기초~
July 19, 2016
Anim.Compression type如果是Optimal的话
Comments
Post a Comment
덧글쓰기 기능 있는거 아시죠? ㅋㅋ