|
|
@@ -1,9 +1,5 @@
|
|
|
#include "Crown.h"
|
|
|
#include "Terrain.h"
|
|
|
-#include <cstdlib>
|
|
|
-#include <GL/glew.h>
|
|
|
-#include <GL/glu.h>
|
|
|
-#include "OS.h"
|
|
|
#include "FPSSystem.h"
|
|
|
|
|
|
using namespace crown;
|
|
|
@@ -65,11 +61,6 @@ public:
|
|
|
terrain.PlotCircle(8, 8, 8, 2);
|
|
|
}
|
|
|
|
|
|
- if (event.key == KC_F5)
|
|
|
- {
|
|
|
- terrain.SaveAsBmp("blah.bmp");
|
|
|
- }
|
|
|
-
|
|
|
if (event.key == KC_SPACE)
|
|
|
{
|
|
|
if (cam)
|
|
|
@@ -85,35 +76,30 @@ public:
|
|
|
{
|
|
|
mouseLeftPressed = true;
|
|
|
|
|
|
- GLint view[4];
|
|
|
- GLdouble proj[16], model[16];
|
|
|
+ //GLint view[4];
|
|
|
+ //GLdouble proj[16], model[16];
|
|
|
|
|
|
- glGetDoublev(GL_MODELVIEW_MATRIX, model);
|
|
|
- glGetDoublev(GL_PROJECTION_MATRIX, proj);
|
|
|
- glGetIntegerv(GL_VIEWPORT, view);
|
|
|
+ //glGetDoublev(GL_MODELVIEW_MATRIX, model);
|
|
|
+ //glGetDoublev(GL_PROJECTION_MATRIX, proj);
|
|
|
+ //glGetIntegerv(GL_VIEWPORT, view);
|
|
|
|
|
|
- int x = event.x;
|
|
|
- int y = event.y;
|
|
|
+ //int x = event.x;
|
|
|
+ //int y = event.y;
|
|
|
|
|
|
// Adjust y wndCoord
|
|
|
- y = (625 - y);
|
|
|
+ //y = (625 - y);
|
|
|
|
|
|
- double sX, sY, sZ;
|
|
|
- double eX, eY, eZ;
|
|
|
+ //double sX, sY, sZ;
|
|
|
+ //double eX, eY, eZ;
|
|
|
|
|
|
- gluUnProject(x, y, 0.0f, model, proj, view, &sX, &sY, &sZ);
|
|
|
- gluUnProject(x, y, 1.0f, model, proj, view, &eX, &eY, &eZ);
|
|
|
+ //gluUnProject(x, y, 0.0f, model, proj, view, &sX, &sY, &sZ);
|
|
|
+ //gluUnProject(x, y, 1.0f, model, proj, view, &eX, &eY, &eZ);
|
|
|
|
|
|
- Vec3 dir = Vec3(eX, eY, eZ) - Vec3(sX, sY, sZ);
|
|
|
+ //Vec3 dir = Vec3(eX, eY, eZ) - Vec3(sX, sY, sZ);
|
|
|
|
|
|
- dir.normalize();
|
|
|
+ //dir.normalize();
|
|
|
|
|
|
- //ray.origin = cam->GetPosition();
|
|
|
- ray.direction = dir;
|
|
|
-
|
|
|
- //std::cout << x << " " << y << std::endl;
|
|
|
- //std::cout << "Ori: " << ray.origin.ToStr().c_str() << std::endl;
|
|
|
- //std::cout << "Dir: " << ray.direction.ToStr().c_str() << std::endl;
|
|
|
+ //ray.direction = dir;
|
|
|
}
|
|
|
else if (event.button == MB_RIGHT)
|
|
|
{
|
|
|
@@ -138,9 +124,11 @@ public:
|
|
|
void OnLoad()
|
|
|
{
|
|
|
crown::Renderer* renderer = crown::GetDevice()->GetRenderer();
|
|
|
- renderer->SetClearColor(Color4::LIGHTBLUE);
|
|
|
+
|
|
|
+ renderer->set_clear_color(Color4::LIGHTBLUE);
|
|
|
|
|
|
Vec3 start = Vec3(0.0f, 10.0f, 0.0f);
|
|
|
+
|
|
|
// Add a movable camera
|
|
|
cam = new MovableCamera(/*Vec3::ZERO*/start, true, 90.0f, 1.6f, true, 0.1, 2.5);
|
|
|
|
|
|
@@ -156,20 +144,20 @@ public:
|
|
|
// Add a skybox
|
|
|
skybox = new Skybox(Vec3::ZERO, true);
|
|
|
|
|
|
- if (skybox)
|
|
|
- {
|
|
|
- skybox->SetFace(SF_NORTH, GetTextureManager()->Load("res/red_north.tga"));
|
|
|
- skybox->SetFace(SF_SOUTH, GetTextureManager()->Load("res/red_south.tga"));
|
|
|
- skybox->SetFace(SF_EAST, GetTextureManager()->Load("res/red_east.tga"));
|
|
|
- skybox->SetFace(SF_WEST, GetTextureManager()->Load("res/red_west.tga"));
|
|
|
- skybox->SetFace(SF_UP, GetTextureManager()->Load("res/red_up.tga"));
|
|
|
- skybox->SetFace(SF_DOWN, GetTextureManager()->Load("res/red_down.tga"));
|
|
|
- }
|
|
|
+ //if (skybox)
|
|
|
+ //{
|
|
|
+ // skybox->SetFace(SF_NORTH, GetTextureManager()->Load("res/red_north.tga"));
|
|
|
+ // skybox->SetFace(SF_SOUTH, GetTextureManager()->Load("res/red_south.tga"));
|
|
|
+ // skybox->SetFace(SF_EAST, GetTextureManager()->Load("res/red_east.tga"));
|
|
|
+ // skybox->SetFace(SF_WEST, GetTextureManager()->Load("res/red_west.tga"));
|
|
|
+ // skybox->SetFace(SF_UP, GetTextureManager()->Load("res/red_up.tga"));
|
|
|
+ // skybox->SetFace(SF_DOWN, GetTextureManager()->Load("res/red_down.tga"));
|
|
|
+ //}
|
|
|
|
|
|
terrain.CreateTerrain(64, 64, 1, 0.0f);
|
|
|
|
|
|
- grass = GetTextureManager()->Load("res/grass.tga");
|
|
|
- grass->SetFilter(TF_TRILINEAR);
|
|
|
+ //grass = GetTextureManager()->Load("res/grass.tga");
|
|
|
+ //grass->SetFilter(TF_TRILINEAR);
|
|
|
|
|
|
terrain.PlotCircle(4, 4, 4, 2);
|
|
|
|
|
|
@@ -184,8 +172,8 @@ public:
|
|
|
system->set_view_by_cursor();
|
|
|
system->camera_render();
|
|
|
|
|
|
- renderer->_SetLighting(false);
|
|
|
- renderer->_SetTexturing(0, false);
|
|
|
+ renderer->set_lighting(false);
|
|
|
+ renderer->set_texturing(0, false);
|
|
|
|
|
|
if (skybox)
|
|
|
{
|
|
|
@@ -199,21 +187,24 @@ public:
|
|
|
}
|
|
|
|
|
|
/* Render the terrain */
|
|
|
- renderer->_SetAmbientLight(Color4(0.5f, 0.5f, 0.5f, 1.0f));
|
|
|
+ renderer->set_ambient_light(Color4(0.5f, 0.5f, 0.5f, 1.0f));
|
|
|
|
|
|
- renderer->_SetLighting(true);
|
|
|
- renderer->_SetLight(0, true);
|
|
|
- renderer->_SetLightParams(0, LT_DIRECTION, Vec3(0.6, 0.5f, -2.0f));
|
|
|
- renderer->_SetLightColor(0, Color4::WHITE, Color4::WHITE, Color4(0.6f, 0.6f, 0.6f));
|
|
|
- renderer->_SetLightAttenuation(0, 1, 0, 0);
|
|
|
+ renderer->set_lighting(true);
|
|
|
+ renderer->set_light(0, true);
|
|
|
+ renderer->set_light_params(0, LT_DIRECTION, Vec3(0.6, 0.5f, -2.0f));
|
|
|
+ renderer->set_light_color(0, Color4::WHITE, Color4::WHITE, Color4(0.6f, 0.6f, 0.6f));
|
|
|
+ renderer->set_light_attenuation(0, 1, 0, 0);
|
|
|
|
|
|
- renderer->_SetMaterialParams(Color4(0.3f, 0.3f, 0.3f), Color4(0.8f, 0.8f, 0.8f), Color4::BLACK, Color4::BLACK, 0);
|
|
|
+ renderer->set_material_params(Color4(0.3f, 0.3f, 0.3f), Color4(0.8f, 0.8f, 0.8f), Color4::BLACK, Color4::BLACK, 0);
|
|
|
+
|
|
|
+ renderer->set_matrix(MT_MODEL, Mat4::IDENTITY);
|
|
|
+ // Texture disabled because of last updates not in sync... :(
|
|
|
+ //renderer->set_texturing(0, true);
|
|
|
+ //renderer->set_texture(0, grass);
|
|
|
+ renderer->set_lighting(true);
|
|
|
+
|
|
|
+ //glColor3f(1, 1, 1);
|
|
|
|
|
|
- renderer->SetMatrix(MT_MODEL, Mat4::IDENTITY);
|
|
|
- renderer->_SetTexturing(0, true);
|
|
|
- renderer->SetTexture(0, grass);
|
|
|
- renderer->_SetLighting(true);
|
|
|
- glColor3f(1, 1, 1);
|
|
|
terrain.Render();
|
|
|
|
|
|
/* Test for intersection */
|
|
|
@@ -221,7 +212,7 @@ public:
|
|
|
real dist;
|
|
|
if (terrain.TraceRay(ray, tri, tri2, dist))
|
|
|
{
|
|
|
- renderer->_SetDepthTest(false);
|
|
|
+ renderer->set_depth_test(false);
|
|
|
Vec3 intersectionPoint = ray.origin + (ray.direction * dist);
|
|
|
if (mouseLeftPressed)
|
|
|
{
|
|
|
@@ -233,7 +224,7 @@ public:
|
|
|
terrain.ApplyBrush(intersectionPoint, -0.09f);
|
|
|
terrain.UpdateVertexBuffer(true);
|
|
|
}
|
|
|
- renderer->_SetDepthTest(true);
|
|
|
+ renderer->set_depth_test(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -244,8 +235,9 @@ private:
|
|
|
Skybox* skybox;
|
|
|
Mat4 ortho;
|
|
|
Terrain terrain;
|
|
|
- Texture* grass;
|
|
|
- Mesh* cube;
|
|
|
+
|
|
|
+ // Resources
|
|
|
+ ResourceId grass;
|
|
|
|
|
|
bool optShowSkybox;
|
|
|
bool optShowCrate;
|
|
|
@@ -275,9 +267,9 @@ int main(int argc, char** argv)
|
|
|
|
|
|
get_input_manager()->event_loop();
|
|
|
|
|
|
- GetDevice()->GetRenderer()->_BeginFrame();
|
|
|
+ GetDevice()->GetRenderer()->begin_frame();
|
|
|
mainScene.RenderScene();
|
|
|
- GetDevice()->GetRenderer()->_EndFrame();
|
|
|
+ GetDevice()->GetRenderer()->end_frame();
|
|
|
|
|
|
os::swap_buffers();
|
|
|
}
|