[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/astrododge
From:       Rivo Laks <rivolaks () hot ! ee>
Date:       2009-07-08 21:32:00
Message-ID: 1247088720.096498.21474.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 993552 by rivol:

- Readd space rendering. It doesn't procedurally render a sun and its halo anymore. \
Instead, it now renders  a starfield, using a space texture mapped to a cube. In the \
future this could be extended to use cubemap so  that arbitrary background become \
                possible.
- Add a small program that generates the starfield texture by just distributing a \
bunch of points with random  position, size and intensity.

 M  +1 -0      CMakeLists.txt  
 AM            data/textures/space.png  
 M  +27 -5     src/gameview.cpp  
 M  +10 -0     src/gameview.h  
 A             tools (directory)  
 A             tools/CMakeLists.txt  
 A             tools/spacegen.cpp   [License: UNKNOWN]


--- trunk/playground/games/astrododge/CMakeLists.txt #993551:993552
@@ -30,3 +30,4 @@
 add_subdirectory(src)
 add_subdirectory(astrogen)
 add_subdirectory(data)
+add_subdirectory(tools)
** trunk/playground/games/astrododge/data/textures/space.png #property svn:mime-type
   + application/octet-stream
--- trunk/playground/games/astrododge/src/gameview.cpp #993551:993552
@@ -27,6 +27,8 @@
 #include <kgllib/widgetproxy.h>
 #include <kgllib/mesh.h>
 #include <kgllib/fpscounter.h>
+#include <kgllib/texture.h>
+#include <kgllib/shapes.h>
 
 #include <KDebug>
 #include <KStandardDirs>
@@ -49,6 +51,12 @@
 void GameView::init()
 {
     kDebug();
+
+    mSpaceTexture = new KGLLib::Texture(mWorld->dataPath() + "textures/space.png");
+
+    mSpaceMesh = new Mesh();
+    Shapes::createCube(mSpaceMesh);
+    mSpaceMesh->setTexture(mSpaceTexture);
 }
 
 void GameView::setupWorldView()
@@ -73,21 +81,21 @@
 
     // Clear buffers
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-    glEnable(GL_DEPTH_TEST);
 
     // Set up matrices
     glMatrixMode(GL_PROJECTION);
     glPushMatrix();
     glMatrixMode(GL_MODELVIEW);
     setupWorldView();
+
+    // Render space (background). For this, we don't want depth testing, lighting, \
etc +    glDisable(GL_DEPTH_TEST);
+    renderSpace();
+
     // Setup light pos
     glLightfv(GL_LIGHT0, GL_POSITION, Vector4f(-100000.0, 60000.0, 20000.0, \
1.0).data());  glEnable(GL_DEPTH_TEST);
 
-
-    // Render background
-//     renderSpace();
-
     // Render asteroids
     renderAsteroids();
 
@@ -198,3 +206,17 @@
 //     mRenderInfo.totalAsteroids++;
 }
 
+void GameView::renderSpace()
+{
+    glColor3f(1, 1, 1);
+    glEnable(GL_CULL_FACE);
+
+    glPushMatrix();
+    Vector3f shipPos = mWorld->ship()->position();
+    glTranslatef(shipPos.x(), shipPos.y(), shipPos.z());
+    glScalef(100, 100, 100);
+
+    mSpaceMesh->render();
+    glPopMatrix();
+}
+
--- trunk/playground/games/astrododge/src/gameview.h #993551:993552
@@ -18,12 +18,19 @@
 #ifndef GAMEVIEW_H
 #define GAMEVIEW_H
 
+
 #include "glview.h"
 
 class GameWorld;
 class Asteroid;
 
+namespace KGLLib
+{
+    class Texture;
+    class Mesh;
+}
 
+
 class GameView : public GLView
 {
     Q_OBJECT
@@ -42,10 +49,13 @@
 
         void renderAsteroids();
         void renderAsteroid(const Asteroid* a);
+        void renderSpace();
 
     private:
         GameWorld* mWorld;
         float mDetailLevel;
+        KGLLib::Texture* mSpaceTexture;
+        KGLLib::Mesh* mSpaceMesh;
 };
 
 #endif // GAMEVIEW_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic