summaryrefslogtreecommitdiffstats
path: root/src/graphics/common/engine.cpp
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-01 22:59:22 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-01 22:59:22 +0200
commitd9c5a439d09211ec210195709d275596c6c3c9ba (patch)
treeb536721f8ac5f42649345eeb836259bbf6a887e3 /src/graphics/common/engine.cpp
parent9bd4ec03b272e7925b11c3efc2bd8460894ea589 (diff)
downloadcolobot-d9c5a439d09211ec210195709d275596c6c3c9ba.tar.gz
colobot-d9c5a439d09211ec210195709d275596c6c3c9ba.tar.bz2
colobot-d9c5a439d09211ec210195709d275596c6c3c9ba.zip
CGLDevice implementation
- extended Gfx::CDevice interface - written OpenGL implementation in Gfx::CGLDevice - rewrote color and light module - added Gfx::VertexCol - added array casts to Math::Vector, Math::Matrix and Gfx::Color
Diffstat (limited to 'src/graphics/common/engine.cpp')
-rw-r--r--src/graphics/common/engine.cpp106
1 files changed, 74 insertions, 32 deletions
diff --git a/src/graphics/common/engine.cpp b/src/graphics/common/engine.cpp
index 9906a0a..0b92224 100644
--- a/src/graphics/common/engine.cpp
+++ b/src/graphics/common/engine.cpp
@@ -19,68 +19,110 @@
#include "graphics/common/engine.h"
-#include <GL/gl.h>
-#include <GL/glu.h>
+#include "graphics/common/device.h"
+#include "math/geometry.h"
-// TODO implementation
Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
{
+ m_iMan = iMan;
+ m_app = app;
+ m_device = NULL;
+
+ m_wasInit = false;
+
// TODO
}
Gfx::CEngine::~CEngine()
{
+ m_iMan = NULL;
+ m_app = NULL;
+ m_device = NULL;
+
// TODO
}
-std::string Gfx::CEngine::RetError()
+bool Gfx::CEngine::GetWasInit()
+{
+ return m_wasInit;
+}
+
+std::string Gfx::CEngine::GetError()
{
return m_error;
}
-int Gfx::CEngine::OneTimeSceneInit()
+bool Gfx::CEngine::BeforeCreateInit()
{
// TODO
- return 1;
+ return true;
}
-int Gfx::CEngine::Render()
+bool Gfx::CEngine::Create()
{
- /* Just a hello world for now */
+ m_wasInit = true;
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glShadeModel(GL_SMOOTH);
- glDisable(GL_DEPTH_TEST);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+ // TODO
+ return true;
+}
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(-10.0f, 10.0f, -10.0f, 10.0f);
+void Gfx::CEngine::Destroy()
+{
+ // TODO
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ m_wasInit = false;
+}
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+void Gfx::CEngine::SetDevice(Gfx::CDevice *device)
+{
+ m_device = device;
+}
- //glTranslatef(0.0f, 0.0f, -6.0f);
+Gfx::CDevice* Gfx::CEngine::GetDevice()
+{
+ return m_device;
+}
- glBegin(GL_TRIANGLES);
+bool Gfx::CEngine::AfterDeviceSetInit()
+{
+ m_device->SetClearColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f));
+
+ // TODO
+
+ return true;
+}
+
+bool Gfx::CEngine::Render()
+{
+ m_device->BeginScene();
+
+ Math::Matrix world;
+ world.LoadIdentity();
+ m_device->SetTransform(Gfx::TRANSFORM_WORLD, world);
+
+ Math::Matrix view;
+ view.LoadIdentity();
+ m_device->SetTransform(Gfx::TRANSFORM_VIEW, view);
+
+ Math::Matrix proj;
+ Math::LoadOrthoProjectionMatrix(proj, -10.0f, 10.0f, -10.0f, 10.0f);
+ m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, proj);
+
+ Gfx::VertexCol vertices[3] =
{
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex2f(-2.0f, -1.0f);
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex2f(2.0f, -1.0f);
- glColor3f(0.0f, 0.0f, 1.0f);
- glVertex2f(0.0f, 1.5f);
- }
- glEnd();
-
- glFlush();
-
- return 1;
+ Gfx::VertexCol(Math::Vector(-2.0f, -1.0f, 0.0f), Gfx::Color(1.0f, 0.0f, 0.0f)),
+ Gfx::VertexCol(Math::Vector( 2.0f, -1.0f, 0.0f), Gfx::Color(0.0f, 1.0f, 0.0f)),
+ Gfx::VertexCol(Math::Vector( 0.0f, 1.5f, 0.0f), Gfx::Color(0.0f, 0.0f, 1.0f))
+ };
+
+ m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, vertices, 3);
+
+ m_device->EndScene();
+
+ return true;
}