void TemplateGame::redraw() { glClearColor( 78.0/255.0, 114.0/255.0, 136.0/255.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // 3d stuff glhPerspectivef2( m_proj, 40.0, 800.0/600.0, 0.1, 1000.0 ); matrix4x4f xlate, rot; xlate.Translate( 0.0, 0.1, -3.0 ); rot.RotateY( m_rotate ); m_modelview = rot * xlate; m_modelviewProj = m_modelview * m_proj; // Draw 3D scene _draw3d(); // set up 2D draw glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_COLOR_ARRAY ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // 2d stuff // TODO: use shaders glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, 800, 0, 600, -1, 1 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); _draw2d(); }
void TestApp::SceneCollect::init() { // Set up luddite stuff luddite::RenderDeviceGL *renderDeviceGL = new luddite::RenderDeviceGL(); m_renderDevice = renderDeviceGL; // Setup camera (TODO: do this differently) glhPerspectivef2( renderDeviceGL->matProjection, 20.0, 800.0/600.0, 1.0, 500.0 ); matrix4x4f cameraXlate, cameraRot; cameraXlate.Translate(0.0, -4, -15.0); cameraRot.RotateX( 15.0 * (M_PI/180.0) ); renderDeviceGL->matBaseModelView = cameraXlate * cameraRot; // Initialize shader DB m_mtlDB = new luddite::MaterialDB( ); m_mtlDB->initShaderDB(); // Add material def files m_mtlDB->addMaterialDefs("CollectGame.material.xml" ); luddite::Material *mtl = m_mtlDB->getNamedMaterial( m_renderDevice, "mtl.environment" ); // Build scene graph m_worldRoot = new luddite::SceneNode( "worldRoot" ); // Load the ground plane obj file in the center. m_groundPlane = scene_objfile_named( "grid10x10.obj", m_renderDevice, m_mtlDB ); m_worldRoot->addChild( m_groundPlane ); // Load the player mesh m_player = scene_objfile_named( "player.obj", m_renderDevice, m_mtlDB ); m_worldRoot->addChild( m_player ); // Load the trees luddite::SceneNode *tree = scene_objfile_named("tree_fir.obj", m_renderDevice, m_mtlDB ); tree->m_pos = vec3f( 2.0, 0.0, 1.5 ); m_worldRoot->addChild( tree ); m_trees.push_back(tree); // Add tree instances for (int i=0; i <20; i++) { luddite::SceneNode *treeInst = tree->makeInstance(); // Generate a random position for the tree, outside the center of the // map (TODO: also don't overlap other trees) do { vec3f treePos = vec3f( randUniform(-10.0, 10.0), 0.0, randUniform(-10.0, 10.0) ); treeInst->m_pos = treePos; } while (prmath::LengthSquared(treeInst->m_pos) < 1.0 ); m_worldRoot->addChild( treeInst ); m_trees.push_back( treeInst ); } // FIXME.. this is temporary, shouldn't need to do this (and we shouldn't // upload all the shaders, only used ones) m_mtlDB->useAllShaders( m_renderDevice ); // Finally, create scene for our node graph m_scene = new luddite::Scene( m_worldRoot ); }
void mainloop() { CL_OpenGLWindowDescription desc; desc.set_size( CL_Size( 1024, 768 ), true ); CL_DisplayWindow wnd(desc); CL_GraphicContext gc = wnd.get_gc(); glMatrixMode(GL_PROJECTION); //hello // gluPerspective(45, //view angle // 1.0, //aspect ratio // 10.0, //near clip // 200.0);//far clip GLfloat matrix[16]; glhPerspectivef2(matrix, 45, 1.0, 10.0, 200.0 ); glLoadMatrixf( matrix ); glMatrixMode(GL_MODELVIEW); cube c; float rotateBy; CL_Font font(gc, "Helvetica", 24); GUI gui(&wnd); while( true ) { rotateBy += 1; glEnable(GL_CULL_FACE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0,0,-50); glRotatef(rotateBy,1,1,0); glBegin(GL_QUADS); c.redraw(); glEnd(); glPopMatrix(); glDisable( GL_CULL_FACE ); CL_Draw::line(gc, 0, 0, 100, 100, CL_Colorf( 1.0f ,1.0f ,1.0f )); font.draw_text( gc, 100, 100, "bla bla bla", CL_Colorf( 1.0f, 1.0f, 1.0f )); gui.run(&wnd); wnd.flip(); CL_System::sleep( 10 ); CL_KeepAlive::process(); } }