void MapDisp::Render() { Vector2 pts[4]; al_clear_to_color( al_map_rgb( 0, 0, 0 ) ); for( int y = 0; y < MapHeight; y++ ) { for( int x = 0; x < MapWidth; x++ ) { pts[0].X = x * TileSize; pts[1].X = x * TileSize; pts[2].X = (x + 1) * TileSize; pts[3].X = (x + 1) * TileSize; pts[0].Y = y * TileSize; pts[1].Y = (y + 1) * TileSize; pts[2].Y = y * TileSize; pts[3].Y = (y + 1) * TileSize; Cam->AbsoluteToCameraOffset( &pts[0], &pts[0] ); Cam->AbsoluteToCameraOffset( &pts[1], &pts[1] ); Cam->AbsoluteToCameraOffset( &pts[2], &pts[2] ); Cam->AbsoluteToCameraOffset( &pts[3], &pts[3] ); DrawGround( x, y, (Vector2*)&pts ); } } GuiStage::Render(); cursor->Render(); }
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if FIX_FUNCTION glLightfv(GL_LIGHT0, GL_POSITION, g_lightPos); #else if (lightPosLocation1 != -1) { //glUniformMatrix4fv(lightPosLocation, 1, GL_FALSE, lightPos); glUniform3fv(lightPosLocation1, 1, g_lightPos); } #endif glMatrixMode(GL_MODELVIEW); glPushMatrix(); gluLookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glTranslatef(0.0f, 0.0f, -50.0f); float mat[4*4]; ConvertQuaternionToMatrix(g_Rotate, mat); /*float invmat[4*4]; m3dInvertMatrix44(invmat, mat); if (lightPosLocation != -1) { glUniformMatrix4fv(lightPosLocation, 1, GL_FALSE, mat); }*/ glMultMatrixf(mat); DrawGround(); DrawObjects(); glPopMatrix(); TwDraw(); glutSwapBuffers(); glutPostRedisplay(); }
// Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); frameCamera.ApplyCameraTransform(); // Position light before any other transformations glLightfv(GL_LIGHT0, GL_POSITION, fLightPos); // Draw the ground glColor3f(0.60f, .40f, .10f); DrawGround(); // Draw shadows first glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glPushMatrix(); glMultMatrixf(mShadowMatrix); DrawInhabitants(1); glPopMatrix(); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); // Draw inhabitants normally DrawInhabitants(0); glPopMatrix(); // Do the buffer Swap glutSwapBuffers(); glutPostRedisplay(); }
void QuadTree::DrawGround(QuadTreeNode* node,Frustum* frust){ vec3 testVec(node->position.x,0.0f,node->position.y); if(!frust->CheckRect(testVec,node->size/2.0f)){ node->culled = true; return; } node->culled = false; int count = 0; for(int child = 0; child < 4; child++){ if(node->nodes[child] != 0){ count++; DrawGround(node->nodes[child],frust); } } if(count!=0) return; if(node->indices){ int numIndices = node->triangleCount * 3; glDrawElements(GL_TRIANGLES,numIndices,GL_UNSIGNED_INT,node->indices); m_drawCount += node->triangleCount; } }
/////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); // Move light under floor to light the "reflected" world glLightfv(GL_LIGHT0, GL_POSITION, fLightPosMirror); glPushMatrix(); glFrontFace(GL_CW); // geometry is mirrored, swap orientation glScalef(1.0f, -1.0f, 1.0f); DrawWorld(); glFrontFace(GL_CCW); glPopMatrix(); // Draw the ground transparently over the reflection glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawGround(); glDisable(GL_BLEND); glEnable(GL_LIGHTING); // Restore correct lighting and draw the world correctly glLightfv(GL_LIGHT0, GL_POSITION, fLightPos); DrawWorld(); glPopMatrix(); // Do the buffer Swap glutSwapBuffers(); }
/** * Display callback. Draws the curves, points, and object */ void Display(void) { // clear buffers glClear(GL_COLOR_BUFFER_BIT); DrawGround(); // draw the ground // option to hide the controls if (!hide) { DrawControlPoints(); // draw all control points DrawAnimationPoints(); // draw the path for animation } // which scene if (scene1) { DrawBall(); // draw the ball } else { DrawLamp(); // draw the pixar lamp } glutSwapBuffers(); }
void QuadTree::DrawGround(Frustum* frust){ m_drawCount = 0; glBindVertexArray(m_vertexBuffer->GetVAO()); DrawGround(m_root,frust); glBindVertexArray(0); }
void RenderGame() { opengl->StartDraw(); opengl->CreateViewport(true, 800,500,0,100,0.0f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0, 1.0, 1.0); glTranslatef(0.0f, 0.0f, -25.0f); //Sets camera glRotatef(30.0f, 1.0, 0.0, 0.0); glRotatef(-30.0f, 0.0, 1.0, 0.0); DrawGround(imgbtnStart->ID); float velocity[3]; velocity[0] = velocity[2] = cgl::GetRandomFloat(-0.1, 0.1); velocity[1] = cgl::GetRandomFloat(-.02, -0.04); float position[3]; position[0] = cgl::GetRandomFloat(-5.0, 5.0); position[2] = cgl::GetRandomFloat(-5.0, 5.0); position[1] = 15; weather->StartOneParticle(velocity, position); weather->Draw(); opengl->CreateViewport2D(SCREENWIDTH,SCREENHEIGHT,0, 0, 0, 0); //Drawing text requires viewport 2D, with Z far and Z near to be 0//equal each other text->SetFontSize(16); text->Draw("Kills:", -SCREENWIDTH,SCREENHEIGHT-50); text->Draw("Deaths", -SCREENWIDTH,SCREENHEIGHT-100); text->Draw("Water", -SCREENWIDTH,SCREENHEIGHT-150); text->Draw("Leafs", -SCREENWIDTH,SCREENHEIGHT-200); if(messageFeedback != "") { //Center "error" message, "cannot move there", "cannot attack this object", "Died", "Killed player X" textFeedback->Draw((char*)messageFeedback.c_str(), -SCREENWIDTH,SCREENHEIGHT/2); } opengl->CreateViewport2D(SCREENWIDTH,SCREENHEIGHT,0, 0, 0, 1); //Drawing buttons requires Viewport 2D, with z far and near not equal each other imgMenu->Draw(SCREENWIDTH-50,SCREENHEIGHT-50, 50,50, true); //imgMenu->Draw(0,0, 32, 32, true); //opengl->CreateViewport3D(600,600,0,0,0.1, 1000); if(gamestate > 1) //Viewing a menu while playing { opengl->CreateViewport2D(SCREENWIDTH,SCREENHEIGHT,0, 0, 0, 1); //Drawing buttons requires Viewport 2D, with z far and near not equal each other btnCancel->Draw(); btnQuitGame->Draw(); //Images will not draw, what so ever? //imgMenu->Draw(0,0, true); //imgMenu->Draw(50,50, true); //imgMenu->Draw(0,0, false); //imgMenu->Draw(50,50, false); } opengl->EndDraw(); }
static void UpdateNormal() { // Camera update glLoadIdentity(); gluLookAt( 0, cam_height, cam_dist, 0, /*My_Abs(My_Sin(cam_rot/20)*20)*/17, 0, 0, 1, 0 ); glRotatef( cam_rot, 0, 1, 0 ); cam_rot += 0.5f; DrawGround(); DrawDome(); }
void Render() { float alpha = GetTickCount()/10.0f; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1,1,1); DrawLight(); DrawGround(); DrawCylinder(alpha, true); DrawCylinder(alpha, false); }
/* 로봇이 로켓을 날리는 모습을 표현한 함수 */ void Rocket(){ sndPlaySound(TEXT("C:\\sample2.wav"), SND_ASYNC | SND_NOSTOP); glLoadIdentity(); //CTM 초기화 /*90도 각도로 팔을 앞으로 내민다*/ L_Arm_x = -90; R_Arm_x = -90; R = 2 * abs(-sin(time2)*0.2 - 0.2) + 0.2;//우측 로켓 움직임 설정 //abs절대값으로 로켓이 앞쪽으로 나가게 설정. //+0.2를 통해 로켓의 처음위치 조절. 2*를 통해 로켓이 나가는 거리조절. //sin()함수를 통해 주기적인 움직임 설정. R2 = 2 * abs(sin(time2)*0.2 - 0.2) + 0.2;//좌측 로켓 움직임 설정 //abs절대값으로 로켓이 앞쪽으로 나가게 설정. //+0.2를 통해 로켓의 처음위치 조절. 2*를 통해 로켓이 나가는 거리조절. //sin()함수를 통해 주기적인 움직임 설정. R_Leg_y = abs(-sin(time) * 30 - 30); //우측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) L_Leg_y = abs(sin(time) * 30 - 30); //좌측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) R_Leg_x = sin(time) * 60; //우측다리는 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 L_Leg_x = -R_Leg_x; //좌측다리는 우측다리반대로 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 ////////////////display//////////////// cyl = gluNewQuadric(); //실린더 객체 생성 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //초기화 glMatrixMode(GL_MODELVIEW); //모드 설정 DrawGround(); //지면 호출 glLoadIdentity(); //CTM 초기화 glPushMatrix();// 처음 저장 좌표 다시 저장 glRotatef(-230.0, 0, 1, 0); //y축 기준으로 회전 /* 로봇이 로켓을 쏠 때 상,하,좌,우로 몸을 트는 모습을 설정 */ glRotatef(-abs(sin(time) * 8), 1, 0, 0); //x축으로 8도 까지 각도틀어짐(abs절대값을 줌으로써 몸체가 뒤로 꺾이지 않는 한계점을 설정) glRotatef(sin(time) * 7, 0, 0, 1); //z축으로 7도 까지 각도틀어짐, sin()함수를 사용하여 주기적인 움직임 설정 /* 로봇이 로켓을 날리며 몸을 튕기는 모습을 표현 */ float i = 0; i = abs(sin(time)*0.08); //i값 설정 glTranslatef(0.0, i, 0); //변수 i만큼 이동 glTranslatef(0.0, 0.5, 0.0);//최초 위치 DrawAndroid(); glutSwapBuffers(); }
/* 로봇이 달리는 것을 표현한 함수. 로봇의 관절이 움직이는 것을 표현했고, 로봇이 달리면서 상,하,좌,우로 움직이는 모습을 표현했다. */ void Run(){ sndPlaySound(TEXT("C:\\sample1.wav"), SND_ASYNC | SND_NOSTOP); glLoadIdentity();//CTM 초기화 /* 기본적인 로봇의 움직임의 가속도는 sin() 함수를 통해 표현하였다 또한 관절의 제한범위를 생각하여 abs() 함수를 통해 관절의 움직임을 제한하였다. */ L_Arm_x = sin(time) * 80; //왼팔은 80도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 R_Arm_x = -L_Arm_x; //오른팔은 왼팔반대로 80도각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정. R_Arm_y = -abs(sin(time) * 60 + 50); //우측팔뚝 각도조절(abs절대값을 줌으로써 팔뚝이 뒤로꺾이지 않는 한계점을 설정) L_Arm_y = -abs(-sin(time) * 60 + 50); //좌측팔뚝 각도조절(abs절대값을 줌으로써 팔뚝이 뒤로꺾이지 않는 한계점을 설정) R_Leg_y = abs(-sin(time) * 30 - 30); //우측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) L_Leg_y = abs(sin(time) * 30 - 30); //좌측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) R_Leg_x = sin(time) * 60; //우측다리는 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 L_Leg_x = -R_Leg_x; //좌측다리는 우측다리반대로 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 ////////////////display//////////////// cyl = gluNewQuadric(); //실린더 객체 생성 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //초기화 glMatrixMode(GL_MODELVIEW); //모드 설정 DrawGround(); //지면 호출 glLoadIdentity();//CTM 초기화 /* 로봇이 달리면서 앞,뒤로 뒤뚱거리고 몸이 틀어지는 것을 표현 */ glRotatef(-230.0, 0, 1, 0);//y축으로 기울임 glRotatef(abs(sin(time) * 16), 1, 0, 0);//x축으로 16도 까지 각도틀어짐(abs절대값을 줌으로써 몸체가 뒤로 꺾이지 않는 한계점을 설정) glRotatef(sin(time) * 16, 0, 1, 0); //y축으로 16도 까지 각도틀어짐, sin()함수를 사용하여 주기적인 움직임 설정 /* 로봇이 달리면서 상,하로 움직이는 것을 표현 */ float i = 0; i = abs(sin(time)*0.08); //i변수값 설정 glPushMatrix();// 처음 저장 좌표 다시 저장 glTranslatef(0.0, i, 0); //변수 i만큼 로봇의 몸체가 Y축기준으로 움직임. glTranslatef(0.0, 0.5, 0.0);//최초 로봇의 위치 DrawAndroid(); glutSwapBuffers(); }
void Display() { // Clear the color and depth buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Save the current modelview matrix (the identity matrix) modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); if (reflecting) { // Draw the "reflection" of the scene upside down modelViewMatrix.PushMatrix(); // Flip the y-axis last. modelViewMatrix.Scale(1.0f, -1.0f, 1.0f); // The scene is essentially in a pit, bo elevate it an equal distance from the // x-z plane to ensure that its reflection will appear to be below the ground. modelViewMatrix.Translate(0.0f, -2.0f * FLOOR_HEIGHT, 0.0f); // Reverse the orientation of all polygonsm in the scene so the orientation of // their reflections will produce the same lighting as the above-ground scene. glFrontFace(GL_CW); DrawScene(); glFrontFace(GL_CCW); modelViewMatrix.PopMatrix(); } DrawGround(); DrawScene(); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Tell GLUT to do it again glutPostRedisplay(); }
// Called to draw scene void RenderScene(void) { int i; static GLfloat yRot = 0.0f; // Rotation angle for animation yRot += 0.5f; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); frameCamera.ApplyCameraTransform(); // Draw the ground DrawGround(); // Draw the randomly located spheres for(i = 0; i < NUM_SPHERES; i++) { glPushMatrix(); spheres[i].ApplyActorTransform(); glutSolidSphere(0.1f, 13, 26); glPopMatrix(); } glPushMatrix(); glTranslatef(0.0f, 0.0f, -2.5f); glPushMatrix(); glRotatef(-yRot * 2.0f, 0.0f, 1.0f, 0.0f); glTranslatef(1.0f, 0.0f, 0.0f); glutSolidSphere(0.1f, 13, 26); glPopMatrix(); glRotatef(yRot, 0.0f, 1.0f, 0.0f); gltDrawTorus(0.35, 0.15, 40, 20); glPopMatrix(); glPopMatrix(); // Do the buffer Swap glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); frameCamera.ApplyCameraTransform(); // Position light before any other transformations glLightfv(GL_LIGHT0, GL_POSITION, fLightPos); // Draw the ground glColor3f(1.0f, 1.0f, 1.0f); DrawGround(); // Draw shadows first glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_STENCIL_TEST); glPushMatrix(); glMultMatrixf(mShadowMatrix); DrawInhabitants(1); glPopMatrix(); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); // Draw inhabitants normally DrawInhabitants(0); glPopMatrix(); // Do the buffer Swap glutSwapBuffers(); }
/* 로봇이 잽을 날리는 것을 표현한 함수 */ void Jap(){ sndPlaySound(TEXT("C:\\sample3.wav"), SND_ASYNC | SND_NOSTOP); glLoadIdentity();//CTM 초기화 /* 로봇의 기본적인 관절의 움직임 범위를 제한하는 곳 */ L_Arm_x = (-40) + sin(time2) * 60;//왼쪽 어깨의 각도시작은 -40상태에서 sin()함수를 사용하여 주기적인 움직임 설정 R_Arm_x = (-80) - L_Arm_x; //우측 어깨의 각도시작은 -80상태에서 왼쪽어깨 움직임의 반대로 설정 R_Arm_y = -abs(cos(time2) * 80); //우측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용) L_Arm_y = -abs(-cos(time2) * 80); //좌측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용) R_Leg_y = abs(-sin(time) * 30 - 20); //우측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) L_Leg_y = abs(sin(time) * 30 - 20); //좌측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) R_Leg_x = sin(time) * 30; //우측다리는 30도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 L_Leg_x = -R_Leg_x; //좌측다리는 우측다리반대로 30도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 ////////////////display//////////////// cyl = gluNewQuadric(); //실린더 객체 생성 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //초기화 glMatrixMode(GL_MODELVIEW); //모드 설정 DrawGround(); //지면 호출 glLoadIdentity(); //CTM 초기화 glRotatef(-230.0, 0, 1, 0); //y축기준으로 회전 glRotatef(sin(time) * 10, 0, 0, 1);//로봇의 좌,우 반동 표현(좌우로 10도 만큼 주기적인 움직임 설정) /* 로봇이 잽을 날리면서 상,하로 움직이는 것을 표현 */ float j = 0; j = abs(sin(time2)*0.085);// j값 설정 glPushMatrix();// 처음 저장 좌표 다시 저장 glTranslatef(0.0, j, 0); //변수 j만큼 로봇의 몸체가 Y축기준으로 움직임. glTranslatef(0.0, 0.5, 0.0);//최초 위치 DrawAndroid(); glutSwapBuffers(); }
static void Display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* viewing */ glPushMatrix(); glRotatef(Xrot, 1.0, 0.0, 0.0); glRotatef(Yrot, 0.0, 1.0, 0.0); /* ground */ glDisable(GL_LIGHTING); glPushMatrix(); glTranslatef(0.0, -1.6, 0.0); DrawGround(); glPopMatrix(); /* logo */ glPushMatrix(); glScalef(2.5, 2.5, 2.5); DrawLogo(); glPopMatrix(); /* pony */ { float xPos, zPos; xPos = WalkRadius * cos(WalkAngle * M_PI / 180.0); zPos = WalkRadius * sin(WalkAngle * M_PI / 180.0); glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(xPos, 0.0, zPos); glRotatef(-WalkAngle + 90.0, 0.0, 1.0, 0.0); DrawPony(LegAngle); glPopMatrix(); } glPopMatrix(); glutSwapBuffers(); }
//=========================================================// //=========================================================// static void display(void) { update_camera(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); // position the light GLfloat pos[4] = { 5.0, 5.0, 5.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, pos); // rotation is used for animation static GLfloat rotation = 0.0; // it's increased by one every frame rotation += 0.1*horseSpeed; // and ranges between 0 and 360 if (rotation > 360.0) rotation = 0.0; //glDisable(GL_LIGHTING); glColor3d(0.1, 0.1, 0.4); output(5, -6, "Mignon Kramp / A385 Computer Graphics"); output(4.5, -6, "- LR move leftright"); output(4, -6, "- look up or down: A / Z"); output(3.5, -6, "- look right/left: arrows ->/<-"); output(3, -6, "- walk forward/backward: arrows UP/Down"); output(2.5, -6, "XYZ " + std::to_string(horse.angle)); DrawGround(); DrawLinesXYZ(); UpdateHorse(); glutSwapBuffers(); }
void renderScene() { glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // turn on lights light.turnOn(); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -cRadius); glRotatef(xCamRot,1.0,0.0,0.0); glRotatef(yCamRot, 0.0, 1.0, 0.0); glTranslated(-xCam, 0.0f, -zCam); //translate the screen shader.bind(); // draw ground DrawGround(); // draw primitives draw(); shader.unBind(); glutSwapBuffers(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //清空颜色缓冲和深度缓冲 DrawGround(); DrawSky(); glColor3f(0.8, 0.8, 0.8); glPushMatrix(); //robot的位置和方向设置 glTranslatef(centerX, centerY, centerZ); glRotatef(angle, 0.0, 1.0, 0.0); glColor3f(0.5, 0.5, 0.5); //设置颜色为灰色 glPushMatrix(); //画出左大腿 glColor3f(0.5, 0.5, 0.5); glRotatef((GLfloat)leftHigherLegAngle, 0, 0, 1.0); glTranslatef(0.5*leg_x / 2, 0.0, leg_z * 0.5); glPushMatrix(); glScalef(leg_x, leg_y, leg_z); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glTranslatef(0.5 * leg_x / 2, 0.0, 0.0); //画关节 glPushMatrix(); glTranslatef(0.0, 0.0, -0.5*leg_z / 2); gluCylinder(quadratic, 0.5 * leg_y / 2, 0.5 * leg_y / 2, leg_z * 0.5, 32, 32); glPopMatrix(); glRotatef(LeftLowerLegAngle, 0.0, 0.0, 1.0); //画左小腿 glTranslatef(0.5*leg_x / 2, 0.0, 0.0); glPushMatrix(); glColor3f(0.5, 0.5, 0.5); glScalef(leg_x - 0.2, leg_y - 0.2, leg_z - 0.2); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glTranslatef(0.5*leg_x / 2, 0.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glTranslatef(-0.5*foot_x / 2 + 0.5*foot_y / 2, 0.0, 0.0); glRotatef(leftFootAngle, 0.0, 0.0, 1.0); glPushMatrix(); glScalef(foot_x, foot_y, foot_z); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glPopMatrix(); glPushMatrix(); //画出右大腿 glColor3f(0.25, 0.45, 0.25); glRotatef((GLfloat)rightHigherLegAngle, 0, 0, 1.0); glTranslatef(leg_x / 4, 0.0, -leg_z / 2); glPushMatrix(); glScalef(leg_x, leg_y, leg_z); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glTranslatef(leg_x / 4, 0, 0); //画关节 glPushMatrix(); glTranslatef(0.0, 0.0, -leg_z / 4); gluCylinder(quadratic, leg_y / 4, leg_y / 4, leg_z / 2, 32, 32); glPopMatrix(); glRotatef(rightLowerLegAngle, 0.0, 0.0, 1.0); //画左小腿 glTranslatef(leg_x / 4, 0.0, 0.0); glPushMatrix(); glColor3f(0.5, 0.5, 0.5); glScalef(leg_x - 0.2, leg_y - 0.2, leg_z - 0.2); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glTranslatef(leg_x / 4, 0.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glTranslatef(-foot_x / 4 + leg_y / 4, 0.0, 0.0); glRotatef(rightFootAngle, 0.0, 0.0, 1.0); glPushMatrix(); glScalef(foot_x, foot_y, foot_z); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glPopMatrix(); // 身体 glColor3f(1.0, 1.0, 1.0); glPushMatrix(); glColor3f(0.65, 0.45, 0.45); glTranslatef(0, body_y / 4, 0.0); drawCube(body_x, body_y, body_z); glPopMatrix(); glPushMatrix(); //脖子 glColor3f(0.25, 0.75, 0.75); glTranslatef(0, 0.5*body_y, 0); glScalef(neck_x, neck_y, neck_z); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); // 头部 glPushMatrix(); glColor3f(0.5, 0.5, 0.5); glTranslatef(0, 0.5*body_y + 0.5*head_y, 0); drawCube_head(head_x, head_y, head_z); glPopMatrix(); glColor3f(0.5, 0.55, 0.55); glPushMatrix(); //画左手 glColor3f(0.5, 0.6, 0.6); glTranslatef(0, 0.5*body_y, 0.0); glRotatef(leftHigherHandAngle, 0.0, 0.0, 1.0); glTranslatef(arm_x / 4, 0.0, (body_z + arm_z) / 4); glPushMatrix(); glScalef(arm_x - 0.1, arm_y - 0.1, arm_z - 0.1); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glTranslatef(arm_x / 4, 0.0, 0.0); glPushMatrix(); glColor3f(0.5, 0.55, 0.55); glTranslatef(0.0, 0.0, -arm_z / 4); gluCylinder(quadratic, arm_y / 4, arm_y / 4, arm_z*0.5, 32, 32); glPopMatrix(); glRotatef(leftLowerHandAngle, 0.0, 0.0, 1.0); glTranslatef(arm_x / 4, 0.0, 0.0); glPushMatrix(); glScalef(arm_x - 0.1, arm_y - 0.1, arm_z - 0.1); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glPopMatrix(); glPushMatrix(); //画右手 glColor3f(0.5, 0.55, 0.55); glTranslatef(0, body_y / 2, 0.0); glRotatef(rightHigherHandAngle, 0.0, 0.0, 1.0); glTranslatef(arm_x / 4, 0.0, -(body_z + arm_z) / 4); glPushMatrix(); glScalef(arm_x, arm_y, arm_z); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glTranslatef(arm_x / 4, 0.0, 0.0); glPushMatrix(); glColor3f(0.5, 0.55, 0.55); glTranslatef(0.0, 0.0, -arm_z / 4); gluCylinder(quadratic, arm_y / 4, arm_y / 4, arm_z*0.5, 32, 32); glPopMatrix(); glRotatef(rightLowerHandAngle, 0.0, 0.0, 1.0); glTranslatef(arm_x / 4, 0.0, 0.0); glPushMatrix(); glScalef(arm_x - 0.1, arm_y - 0.1, arm_z - 0.1); glutSolidCube(GLOBAL_SIZE); glPopMatrix(); glPopMatrix(); glPopMatrix(); glFlush(); glutSwapBuffers(); }
int setup(void) { GLuint major, minor; GLint success; GLuint model_id; srand( (unsigned)time( NULL ) ); // Make sure required functionality is available! if (!getGLversion( &major, &minor)) return -1; if (major < 2) { printf("<!> OpenGL 2.0 or higher is required\n"); return -1; } windowpos = IsExtSupported("GL_ARB_window_pos"); // Make sure required functionality is available! if (!(IsExtSupported("GL_ARB_vertex_program"))) { printf("<!> ARB vertex program extension not supported\n"); return -1; } if (!(IsExtSupported("GL_ARB_fragment_program"))) { printf("<!> ARB fragment program extension not supported\n"); return -1; } if (!(IsExtSupported("GL_ARB_vertex_shader"))) { printf("<!> ARB vertex shader extension not supported\n"); return -1; } if (!(IsExtSupported("GL_ARB_fragment_shader"))) { printf("<!> ARB fragment shader extension not supported\n"); return -1; } if (!(IsExtSupported("GL_EXT_framebuffer_object"))) { printf("<!> Framebuffer object extension not supported\n"); return -1; } //Define extension prointers glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)glXGetProcAddressARB("glGenFramebuffersEXT"); glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)glXGetProcAddressARB("glBindFramebufferEXT"); glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)glXGetProcAddressARB("glFramebufferTexture2DEXT"); glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)glXGetProcAddressARB("glGenRenderbuffersEXT"); glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)glXGetProcAddressARB("glBindRenderbufferEXT"); glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)glXGetProcAddressARB("glRenderbufferStorageEXT"); glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)glXGetProcAddressARB("glFramebufferRenderbufferEXT"); glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)glXGetProcAddressARB("glDeleteFramebuffersEXT"); glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)glXGetProcAddressARB("glDeleteRenderbuffersEXT"); glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)glXGetProcAddressARB("glCheckFramebufferStatusEXT"); if ( !glGenFramebuffersEXT || !glBindFramebufferEXT || !glFramebufferTexture2DEXT || !glGenRenderbuffersEXT || !glBindRenderbufferEXT || !glRenderbufferStorageEXT || !glFramebufferRenderbufferEXT || !glDeleteFramebuffersEXT || !glDeleteRenderbuffersEXT || !glCheckFramebufferStatusEXT ) { printf("<!> Required extension not supported\n"); return -1; } //Enable smooth shading glShadeModel(GL_SMOOTH); //Enable depth testing glEnable(GL_DEPTH_TEST); glPolygonOffset( scalePoly, biasPoly ); //Enable backface culling glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace( GL_CW ); //Background color (Ligth blue) glClearColor(0.0f, 0.4f, 0.8f, 1.0f); //Generate texture objects texture_id = (GLuint *)malloc( NUM_TEXTURES * sizeof(GLuint) ); glGenTextures( NUM_TEXTURES, texture_id ); // Enable Anisotropic filtering (for 2D textures only) if( enable_anisotropic ) { glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &MaxAnisoLevel); if( AnisoLevel > MaxAnisoLevel) AnisoLevel = MaxAnisoLevel; if( print_info ) printf("<-> %.0fX anisotropic filtering enabled\n", AnisoLevel); } else AnisoLevel = 0.0f; // Enable FSAA if (enable_fsaa) glEnable(GL_MULTISAMPLE); //Load MD2 models and textures for (model_id = 0; model_id < NUM_MODELS; ++model_id) { // Load the .md2 model if ( (md2_model[model_id] = (MD2_MODEL_PTR)malloc(sizeof(MD2_MODEL))) == NULL) { printf("<!> Unable to allocate memory for MD2 model in %s\n", filename[3*model_id]); return -1; } if ( !LoadMD2(md2_model[model_id], filename[3*model_id]) ) { printf("<!> Unable to load MD2 model from %s\n", filename[3*model_id]); return -1; } if( print_info ) printf("<-> Loaded MD2 model from \"%s\" for model #%d\n", filename[3*model_id], model_id); // Load texture from disk if ( !LoadImageFromDisk(md2_model[model_id]->skin, filename[3*model_id+1]) ) { printf("<!> Unable to load texture from %s \n", filename[3*model_id+1]); return -1; } if( print_info ) printf("<-> Loaded texture from \"%s\" for model #%d\n", filename[3*model_id+1], model_id); //Set up model texture parameters glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, md2_model[model_id]->skin->components, md2_model[model_id]->skin->width, md2_model[model_id]->skin->height, 0, md2_model[model_id]->skin->format, GL_UNSIGNED_BYTE, md2_model[model_id]->skin->data); // Load normal from disk if ( !LoadImageFromDisk(md2_model[model_id]->normal, filename[3*model_id+2]) ) { printf("<!> Unable to load texture from %s \n", filename[3*model_id+2]); return -1; } if( print_info ) printf("<-> Loaded texture from \"%s\" for model #%d\n", filename[3*model_id+2], model_id); //Set up model texture parameters glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id+1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, md2_model[model_id]->normal->components, md2_model[model_id]->normal->width, md2_model[model_id]->normal->height, 0, md2_model[model_id]->normal->format, GL_UNSIGNED_BYTE, md2_model[model_id]->normal->data); } // Load floor texture from disk floor_texture = (IMAGE_PTR)malloc(sizeof(IMAGE)); floor_texture->data = NULL; if ( !LoadImageFromDisk(floor_texture, filename[3*NUM_MODELS]) ) { printf("<!> Unable to load texture from %s\n", filename[3*NUM_MODELS]); return -1; } if( print_info ) printf("<-> Loaded texture from \"%s\"\n", filename[3*NUM_MODELS]); //Set up floor texture parameters glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (enable_anisotropic) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, AnisoLevel); glTexImage2D( GL_TEXTURE_2D, 0, floor_texture->components, floor_texture->width, floor_texture->height, 0, floor_texture->format, GL_UNSIGNED_BYTE, floor_texture->data); if (floor_texture->data) { free(floor_texture->data); floor_texture->data = NULL; } // Load floor normal map from disk floor_texture = (IMAGE_PTR)malloc(sizeof(IMAGE)); floor_texture->data = NULL; if ( !LoadImageFromDisk(floor_texture, filename[3*NUM_MODELS+1]) ) { printf("<!> Unable to load texture from %s\n", filename[3*NUM_MODELS+1]); return -1; } if( print_info ) printf("<-> Loaded texture from \"%s\"\n", filename[3*NUM_MODELS+1]); //Set up floor texture parameters glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (enable_anisotropic) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, AnisoLevel); glTexImage2D( GL_TEXTURE_2D, 0, floor_texture->components, floor_texture->width, floor_texture->height, 0, floor_texture->format, GL_UNSIGNED_BYTE, floor_texture->data); if (floor_texture->data) { free(floor_texture->data); floor_texture->data = NULL; } // Load and compile low-level shaders glGenProgramsARB(NUM_SHADERS, ids); if (!CompileShader(GL_VERTEX_PROGRAM_ARB, ids[0], DATA_DIR "data/shaders/light.vp")) return -1; if (!CompileShader(GL_FRAGMENT_PROGRAM_ARB, ids[1], DATA_DIR "data/shaders/lightMasked.fp")) return -1; // Create program object and compile GLSL shaders progObj = glCreateProgramObjectARB(); if (!CompileGLSLshaders(&progObj, DATA_DIR "data/shaders/bumpTBN_SH_VP.glsl", DATA_DIR "data/shaders/bumpTBN_SH_FP.glsl", GL_FALSE)) return -1; // Retrieve uniform and attributes locations glUseProgramObjectARB(progObj); colorMap = glGetUniformLocationARB(progObj, "colorMap"); bumpMap = glGetUniformLocationARB(progObj, "bumpMap"); shadowMap = glGetUniformLocationARB(progObj, "shadowMap"); tangent = glGetAttribLocation(progObj, "tangent"); binormal = glGetAttribLocation(progObj, "binormal"); for (model_id = 0; model_id < NUM_MODELS; ++model_id) { md2_model[model_id]->tangent = tangent; md2_model[model_id]->binormal = binormal; } // Set texture units glUniform1i( colorMap, 0 ); glUniform1i( bumpMap, 1 ); glUniform1i( shadowMap, 2 ); //Validate shaders glValidateProgramARB(progObj); glGetObjectParameterivARB(progObj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); if (!success) { GLbyte infoLog[MAX_INFO_LOG_SIZE]; glGetInfoLogARB(progObj, MAX_INFO_LOG_SIZE, NULL, (char *)infoLog); printf("<!> Error in program validation\n"); printf("Info log: %s\n", infoLog); return -1; } //Disable GLSL and enable low-level shaders glUseProgramObjectARB(0); glEnable(GL_VERTEX_PROGRAM_ARB); glEnable(GL_FRAGMENT_PROGRAM_ARB); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ids[0]); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ids[1]); // Create FrameBuffer if (!CreateFB( shadow_sz, &FBO, &shadow_tx )) return -1; //Prebuild the display lists FList = glGenLists(1); glNewList(FList, GL_COMPILE); DrawGround(); glEndList(); //Init animations and kinematic state md2_model[0]->anim_state = ANIMATION_RUN; md2_model[0]->anim_command = ANIMATION_START; md2_model[0]->delta_rate = 30.f; md2_model[0]->position.x = 85.f; md2_model[0]->position.z = 0.f; md2_model[0]->rotation = 90.f; md2_model[1]->anim_state = ANIMATION_RUN; md2_model[1]->anim_command = ANIMATION_START; md2_model[1]->delta_rate = 30.f; md2_model[1]->position.x = 85.f; md2_model[1]->position.z = 0.f; md2_model[1]->rotation = 90.f; md2_model[2]->anim_state = ANIMATION_STANDING_IDLE; md2_model[2]->anim_command = ANIMATION_START; // Set initial camera position and orientation xCam = 0.0f; yCam = 70.0f; zCam = 200.0f; eCam = -0.35f; aCam = 0.0f; lCam = 0.0f; vCam = 0.0f; dCam = 0.0f; //Set initial light aLit = 0.0f; eLit = 0.75f; // Initialise timer gettimeofday(&tv, NULL); t0 = (double)tv.tv_sec + tv.tv_usec / 1000000.0f; t1 = t0; t2 = t0; return 0; }
/* 김연아 선수의 모션을 취하는 함수 */ void Show() { sndPlaySound(TEXT("C:\\sample4.wav"), SND_ASYNC | SND_NOSTOP); glLoadIdentity(); //CTM 초기화 /* 로봇의 기본적인 관절의 움직임 범위를 제한하는 곳 */ L_Arm_x = (-40) + sin(time2) * 60;//왼쪽 어깨의 각도시작은 -40상태에서 sin()함수를 사용하여 주기적인 움직임 설정 R_Arm_x = (-80) - L_Arm_x; //우측 어깨의 각도시작은 -80상태에서 왼쪽어깨 움직임의 반대로 설정 R_Arm_y = -abs(cos(time2) * 10); //우측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용) L_Arm_y = -abs(-cos(time2) * 10); //좌측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용) R_Leg_y = abs(-sin(time) * 30 - 30); //우측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) L_Leg_y = abs(sin(time) * 30 - 30); //좌측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정) R_Leg_x = sin(time) * 60; //우측다리는 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 L_Leg_x = -R_Leg_x; //좌측다리는 우측다리반대로 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정 ////////////////display//////////////// cyl = gluNewQuadric(); //실린더 객체 생성 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //초기화 glMatrixMode(GL_MODELVIEW); //모드 설정 DrawGround(); //지면 호출 glLoadIdentity(); //CTM 초기화 glRotatef(-230.0, 0, 1, 0); //y축기준으로 회전 /* 로봇이 피겨동작시 몸이 틀어지는 것을 표현 */ glRotatef(sin(time) * 7, 0, 0, 1); //z축기준으로 7도 까지 각도틀어짐 (sin()함수를 사용하여 주기적인 움직임 설정) glRotatef(sin(time) * 7, 0, 1, 0); //y축으로 7도 까지 각도틀어짐 (sin()함수를 사용하여 주기적인 움직임 설정) //로봇 몸체 각도 조절 glTranslatef(0.0, 0.18, 0.0); //y축으로 이동 glRotatef(80, 1, 0, 0); //x축 기준으로 회전 glTranslatef(0.0, 0.5, 0.0);//최초 위치 glPushMatrix(); // 처음 저장 위치 DrawBody(0, 0, 0, 0); // 몸통 함수 호출 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 Drawneck(); // 목함수 호출 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //머리 위치 설정 glRotatef(-75, 1, 0, 0); //x축기준으로 회전(머리를 위쪽으로 돌리기) glTranslatef(0.0, -0.02, 0.0); //y축으로 이동 (머리 시작점) DrawHead(); // 머리 호출 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //우측전체팔 위치 설정 DrawR_Arm((R_Arm_y + 30), 1, 0, 0); //우측팔호출 DrawR_Hand(-(R_Arm_y - 15), 1, 0, 0); //우측팔뚝 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //좌측전체팔 위치 설정 glTranslatef(0.0, -0.16, -0.04);//y축,z축으로 이동(좌측팔 시작점) glRotatef(40, 0, 0, 1); //z축 기준으로 회전 DrawL_Arm((L_Arm_y + 30), 1, 0, 0); //좌측팔호출 DrawL_Hand(-(L_Arm_y - 15), 1, 0, 0); //좌측팔뚝 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //좌측전체 다리 위치 설정 glTranslatef(0.0, -0.45, -0.25);//y축,z축으로 이동(좌측다리 시작점) glRotatef(-90, 1, 0, 0); //x축 기준으로 회전 DrawL_Legs(-30, 1, 0, 0); //좌측다리 DrawL_foot(10, 1, 0, 0); //좌측종아리 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glPushMatrix();// 처음 저장 좌표 다시 저장 //우측전체 다리 위치 설정 glTranslatef(0.0, -0.5, -0.5);//y축,z축으로 이동(우측다리 시작점) glRotatef(-90, 1, 0, 0); //x축 기준으로 회전 DrawR_Legs(160, 1, 0, 0); //우측다리 DrawR_foot(R_Leg_y, 1, 0, 0); //우측종아리 glPopMatrix(); // 처음 저장 좌표로 돌아 간다. glutSwapBuffers(); }
////////////////////////////////////////////////// // Draw everything void RenderScene(void) { static int iFrames = 0; // Count frames to calculate fps ever 100 frames static float fps = 0.0f; // Calculated fps // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); frameCamera.ApplyCameraTransform(); // Position light before any other transformations glLightfv(GL_LIGHT0, GL_POSITION, fLightPos); // Draw the ground glColor3f(1.0f, 1.0f, 1.0f); DrawGround(); // Draw shadows first glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_STENCIL_TEST); glPushMatrix(); glMultMatrixf(mShadowMatrix); DrawInhabitants(1); glPopMatrix(); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); // Draw inhabitants normally DrawInhabitants(0); glPopMatrix(); // Calculate Frame Rate, once every 100 frames iFrames++; if(iFrames == 100) { float fTime; // Get the current count LARGE_INTEGER lCurrent; QueryPerformanceCounter(&lCurrent); fTime = (float)(lCurrent.QuadPart - FPSCount.QuadPart) / (float)CounterFrequency.QuadPart; fps = (float)iFrames / fTime; // Reset frame count and timer iFrames = 0; QueryPerformanceCounter(&FPSCount); } // If we have the window position extension, display // the frame rate, and tell if multisampling was enabled // and if the VSync is turned on. if(glWindowPos2i != NULL) { int iRow = 10; char cBuffer[64]; // Turn off depth test, lighting, and texture mapping glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glColor3f(1.0f, 1.0f, 1.0f); // Set position and display message glWindowPos2i(0, iRow); glListBase(nFontList); glCallLists (13, GL_UNSIGNED_BYTE, "OpenGL Rocks!"); iRow+= 20; // Display the frame rate sprintf(cBuffer,"FPS: %.1f", fps); glWindowPos2i(0, iRow); glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer); iRow += 20; // MultiSampled? if(startupOptions.bFSAA == TRUE && startupOptions.nPixelFormatMS != 0) { glWindowPos2i(0, iRow); glCallLists(25 ,GL_UNSIGNED_BYTE,"Multisampled Frame Buffer"); iRow += 20; } // VSync? if(wglSwapIntervalEXT != NULL && startupOptions.bVerticalSync == TRUE) { glWindowPos2i(0, iRow); glCallLists(9 ,GL_UNSIGNED_BYTE, "VSync On"); iRow += 20; } // Put everything back glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); } }
void DrawRoom(glutil::MatrixStack &modelMatrix) { DrawGround(modelMatrix); DrawWall1(modelMatrix); DrawWall2(modelMatrix); }
void Draw (void) // Draw The Scene { Vector3d tmp3d; tmp3d=MView.Matrix() * Vector3d(0.0,100000.0,0.0) + MView.RefPos(); lightPosition[0]=(float)tmp3d(0); lightPosition[1]=(float)tmp3d(1); lightPosition[2]=(float)tmp3d(2); glLightfv(GL_LIGHT1,GL_POSITION,lightPosition); // ROACH QueryPerformanceCounter(&t3); if(InMd5Camera>=1) { Md5Cameras[InMd5Camera].Play(double(t3.QuadPart)/double(feq.QuadPart)); Md5CamerasT[InMd5Camera].Play(double(t3.QuadPart)/double(feq.QuadPart)); } //CMd5CameraTest.Play(double(t3.QuadPart)/double(feq.QuadPart)); if(domulti) glEnable(GL_MULTISAMPLE_ARB); // Enable Our Multisampling // ENDROACH glClearColor(0.0f, 0.0f, 0.0f, 0.5); // Set The Clear Color To Black glClear (GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The View //MFighter.Reset(); ViewPos.UDMplane.Reset(); if(InMd5Camera>=1) { ViewPos.UDMplane.Translate(Vector3d(Md5Cameras[InMd5Camera].CameraPos[0],Md5Cameras[InMd5Camera].CameraPos[2],-Md5Cameras[InMd5Camera].CameraPos[1])); ViewPos.TurnTo(Vector3d(Md5CamerasT[InMd5Camera].CameraPos[0],Md5CamerasT[InMd5Camera].CameraPos[2],-Md5CamerasT[InMd5Camera].CameraPos[1])); } ViewPos.UDPstate.NextState(); ViewPos.UDMplane.RotateInternal(Vector3d(0.0f, CRad(180.0f), 0.0f)); /* Vector3d pos; pos = ViewPos.UDMplane.RefPos(); Vector3d dir; dir = ViewPos.UDMplane.Matrix() * Vector3d(0, 0, -1); Vector3d dir2; dir2 = ViewPos.UDMplane.Matrix() * Vector3d(1, 0, 0); double r = sqrt(pow(dir(0), 2) + pow(dir(2), 2)); if (abs(r)>1){ r = 1.0f; } double latitude = acos_s(r) * 180.0f / PI; double longitude = acos_s(dir(2) / r) * 180.0f / PI; if (dir(0) < 0){ longitude = -longitude; } double intersect[3] = {-dir(2) / r, 0, dir(0) / r}; double rotation = acos_s(dir2(0) * intersect[0] + dir2(1) * intersect[1] + dir2(2) * intersect[2]) * 180.0f / PI; if (dir2(1) < 0){ rotation = -rotation; }*/ ViewPos.UDMplane.RotateInternal(Vector3d(0.0f,0.0f ,- CRad(Getrotation(ViewPos.UDMplane)))); MFighter.RotateInternal(Vector3d(0.0f,0.0f ,- CRad(Getrotation(MFighter)))); MFighter.RotateInternal(Vector3d(CRad(Updown), 0.0f, 0.0f)); MFighter.RotateInternal(Vector3d(0.0f, -CRad(angle), 0.0f)); MFighter.TranslateInternal(Vector3d(posX,-posY,posZ)); if(InMd5Camera>=1) MFighter=ViewPos.UDMplane; MView = (MWorld * MFighter).Invert(); glLoadMatrixd(MView.Matrix4()); glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); glDisable(GL_CULL_FACE); glEnable(GL_FOG); DrawSky(MFighter); //glDisable(GL_TEXTURE_2D); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT1); glDisable(GL_BLEND); glEnable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK,_RenderMode); for(int i=0;i<ModelNumLoaded;i++) { if(i==(ModelNumLoaded-ModelAlphaNumLoaded)) { glDisable(GL_CULL_FACE); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GEQUAL, 0.9f); //glDisable(GL_LIGHT1); //glDisable(GL_LIGHTING); } m_VBMD->ShowVBMD(pModelID[i]); } glEnable(GL_BLEND); glDepthMask(GL_FALSE); DrawGround(); glAlphaFunc(GL_LESS, 0.9f); for(int i=(ModelNumLoaded-ModelAlphaNumLoaded);i<ModelNumLoaded;i++) m_VBMD->ShowVBMD(pModelID[i]); glColor3f(1.0f,1.0f,1.0f); glDepthMask(GL_TRUE); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); glDisable(GL_FOG); //glPushMatrix(); //glTranslated(CMd5CameraTest.CameraView[0],CMd5CameraTest.CameraView[2],-CMd5CameraTest.CameraView[1]); //m_VBMD->ShowVBMD(ballModelID); //glPopMatrix(); //DrawUI(); glDisable(GL_CULL_FACE); glDisable(GL_BLEND); DrawReadme(); if(!doangle) angle-=0.5f; glFlush (); // Flush The GL Rendering Pipeline // ROACH if(domulti) glDisable(GL_MULTISAMPLE_ARB); glColor3f(1.0f,0.5f,0.0f); DrawFPS(); glColor3f(1.0f,1.0f,1.0f); // ENDROACH }
// Called to draw scene void RenderScene(void) { static int iFrames = 0; // Frame count static CStopWatch frameTimer; // Render time // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); frameCamera.ApplyCameraTransform(); // Position light before any other transformations glLightfv(GL_LIGHT0, GL_POSITION, fLightPos); // Draw the ground glColor3f(1.0f, 1.0f, 1.0f); if(iMethod == 0) DrawGround(); else glCallList(groundList); // Draw shadows first glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_STENCIL_TEST); glPushMatrix(); glMultMatrixf(mShadowMatrix); DrawInhabitants(1); glPopMatrix(); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); // Draw inhabitants normally DrawInhabitants(0); glPopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Increment the frame count iFrames++; // Do periodic frame rate calculation if(iFrames == 100) { float fps; char cBuffer[64]; fps = 100.0f / frameTimer.GetElapsedSeconds(); if(iMethod == 0) sprintf(cBuffer,"OpenGL SphereWorld without Display Lists %.1f fps", fps); else sprintf(cBuffer,"OpenGL SphereWorld with Display Lists %.1f fps", fps); glutSetWindowTitle(cBuffer); frameTimer.Reset(); iFrames = 0; } }
void Window::run() { sf::Window window(sf::VideoMode(1920, 1200), "Graphics", sf::Style::Fullscreen, sf::ContextSettings(32, 0, 0, 3, 2)); window.setVerticalSyncEnabled(true); window.setMouseCursorVisible(false); int sizeX = 1920; int sizeY = 1200; int mouseX, mouseY; // init states, load resources resize(1920, 1200); sf::Mouse::setPosition(sf::Vector2i(sizeX/2, sizeY/2), window); // main loop bool running = true; bool leftKeyDown, rightKeyDown, upKeyDown, downKeyDown, kKeyDown, jKeyDown, wKeyDown, aKeyDown, sKeyDown, dKeyDown; while (running) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { running = false; } else if (event.type == sf::Event::Resized) { // window size changed resize(event.size.width, event.size.height); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { running = false; } leftKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::Left); rightKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::Right); upKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::Up); downKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::Down); jKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::J); kKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::K); wKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::W); aKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::A); sKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::S); dKeyDown = sf::Keyboard::isKeyPressed(sf::Keyboard::D); } mouseX = sf::Mouse::getPosition(window).x; mouseY = sf::Mouse::getPosition(window).y; // apply input if (wKeyDown) player.position += player.getLook(); if (sKeyDown) player.position -= player.getLook(); if (aKeyDown) player.position -= player.getRight(); if (dKeyDown) player.position += player.getRight(); glm::mat4 View = player.orientation; View = glm::translate(View, -player.position); glMultMatrixf(glm::value_ptr(View)); // clear buffers glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render scene glMatrixMode(GL_MODELVIEW); DrawGround(); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glm::vec4 ambientLight(1.0f,1.0f,1.0f,1.0f); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glm::value_ptr(ambientLight)); glBegin(GL_POLYGON); glColor3ub(255,0,0); glVertex3f(-10.0,-10.0,0); glColor3ub(0,255,0); glVertex3f(10.0,-10.0,0.0); glColor3ub(0,0,255); glVertex3f(0.0,10.0,0.0); glEnd(); glLoadIdentity(); // move mouse float delta; delta = mouseX - sizeX/2; player.rotate(delta * 0.2f, glm::vec3(0.0f,1.0f,0.0f)); delta = mouseY - sizeY/2; player.rotateRight(delta * 0.2f); sf::Mouse::setPosition(sf::Vector2i(sizeX/2, sizeY/2), window); // swap buffers window.display(); } }
////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering // context. void SetupRC() { M3DVector3f vPoints[3] = {{ 0.0f, -0.4f, 0.0f }, { 10.0f, -0.4f, 0.0f }, { 5.0f, -0.4f, -5.0f }}; int iSphere; int i; // Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]); // Clear stencil buffer with zero, increment by one whenever anybody // draws into it. When stencil function is enabled, only write where // stencil value is zero. This prevents the transparent shadow from drawing // over itself glStencilOp(GL_INCR, GL_INCR, GL_INCR); glClearStencil(0); glStencilFunc(GL_EQUAL, 0x0, 0x01); // Cull backs of polygons glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE_ARB); // Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight); glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight); glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); // Calculate shadow matrix M3DVector4f pPlane; m3dGetPlaneEquation(pPlane, vPoints[0], vPoints[1], vPoints[2]); m3dMakePlanarShadowMatrix(mShadowMatrix, pPlane, fLightPos); // Mostly use material tracking glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight); glMateriali(GL_FRONT, GL_SHININESS, 128); // Randomly place the sphere inhabitants for(iSphere = 0; iSphere < NUM_SPHERES; iSphere++) { // Pick a random location between -20 and 20 at .1 increments spheres[iSphere].SetOrigin(((float)((rand() % 400) - 200) * 0.1f), 0.0, (float)((rand() % 400) - 200) * 0.1f); } // Set up texture maps glEnable(GL_TEXTURE_2D); glGenTextures(NUM_TEXTURES, textureObjects); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for(i = 0; i < NUM_TEXTURES; i++) { GLbyte *pBytes; GLint iWidth, iHeight, iComponents; GLenum eFormat; glBindTexture(GL_TEXTURE_2D, textureObjects[i]); // Load this texture map pBytes = gltLoadTGA(szTextureFiles[i], &iWidth, &iHeight, &iComponents, &eFormat); gluBuild2DMipmaps(GL_TEXTURE_2D, iComponents, iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE, pBytes); free(pBytes); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } // Create display lists groundList = glGenLists(3); sphereList = groundList + 1; torusList = sphereList + 1; // Create sphere display list glNewList(sphereList, GL_COMPILE); gltDrawSphere(0.1f, 40, 20); glEndList(); // Create torus display list glNewList(torusList, GL_COMPILE); gltDrawTorus(0.35, 0.15, 61, 37); glEndList(); // Create the ground display list glNewList(groundList, GL_COMPILE); DrawGround(); glEndList(); }