3D Demo complete

This commit is contained in:
James Turk 2005-08-12 07:21:51 +00:00
parent cc2dd6b333
commit f767e6e2dc

View File

@ -5,12 +5,14 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: State_test.cpp,v 1.1 2005/08/12 07:02:15 cozman Exp $ // $Id: State_test.cpp,v 1.2 2005/08/12 07:21:51 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar #include "FPSDisplayTask.hpp" // used to display FPS in title bar
#include <iostream>
class Demo2D : public State class Demo2D : public State
{ {
public: public:
@ -57,44 +59,50 @@ public:
Application::getInstance().setPerspectiveView(45.0, 1.0, 100.0); Application::getInstance().setPerspectiveView(45.0, 1.0, 100.0);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading glShadeModel(GL_SMOOTH); // smooth shading
glClearDepth(1.0f); // Depth Buffer Setup glClearDepth(1.0f); // set clear depth
glEnable(GL_DEPTH_TEST); // Enables Depth Testing glEnable(GL_DEPTH_TEST); // enable depth testing
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
// create the list to display a box // create the list to display a box
glNewList(boxList, GL_COMPILE); glNewList(boxList, GL_COMPILE);
glBegin(GL_QUADS); glBegin(GL_QUADS);
// front // front - red
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glColor3ub(255, 0, 0);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
// back glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // back - green
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glColor3ub(0, 255, 0);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
// top glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // top - blue
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glColor3ub(0, 0, 255);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
// bottom glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // bottom - orange
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glColor3ub(255, 128, 0);
// right glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // right - purple
// left glColor3ub(128, 0, 255);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
// left - yellow
glColor3ub(255, 255, 0);
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(); glEnd();
glEndList(); glEndList();
} }
@ -116,7 +124,7 @@ public:
{ {
scalar dt = Application::getInstance().getElapsedTime(); scalar dt = Application::getInstance().getElapsedTime();
// dt is sporadic and results in terrible choppiness // dt is sporadic and results in terrible choppiness
dt = 0.01; //dt = 0.01;
xRot += 30*dt; xRot += 30*dt;
yRot += 40*dt; yRot += 40*dt;
@ -127,9 +135,9 @@ public:
{ {
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f); glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(xRot,1.0f,0.0f,0.0f); glRotated(xRot,1.0f,0.0f,0.0f);
glRotatef(yRot,0.0f,1.0f,0.0f); glRotated(yRot,0.0f,1.0f,0.0f);
glRotatef(zRot,0.0f,0.0f,1.0f); glRotated(zRot,0.0f,0.0f,1.0f);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glCallList(boxList); glCallList(boxList);
} }
@ -194,6 +202,11 @@ public:
} }
} }
void update()
{
std::cout << app.getElapsedTime() << "\n";
}
void render() void render()
{ {
video::Color c( font.getColor() ); video::Color c( font.getColor() );