Parcourir la source

Merge more code from the experimental MVP refactor into the old GL code.

legacy
Sam Hocevar sam il y a 13 ans
Parent
révision
e17ba05a9b
2 fichiers modifiés avec 40 ajouts et 55 suppressions
  1. +25
    -20
      src/scene.cpp
  2. +15
    -35
      src/video.cpp

+ 25
- 20
src/scene.cpp Voir le fichier

@@ -38,6 +38,7 @@ struct Tile
#if LOL_EXPERIMENTAL
extern Shader *stdshader;
#endif
extern float4x4 projection_matrix, view_matrix, model_matrix;

/*
* Scene implementation class
@@ -134,15 +135,31 @@ void Scene::Render() // XXX: rename to Blit()
#endif
qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);

// XXX: debug stuff
model_matrix = float4x4::translate(320.0f, 240.0f, 0.0f);
model_matrix = model_matrix * float4x4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
#if 0
static float f = 0.0f;
f += 0.01f;
model_matrix = model_matrix * float4x4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);
model_matrix = model_matrix * float4x4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);
#endif
model_matrix = model_matrix * float4x4::translate(-320.0f, -240.0f, 0.0f);
// XXX: end of debug stuff

#if LOL_EXPERIMENTAL
GLuint uni;
uni = stdshader->GetUniformLocation("model_matrix");
glUniformMatrix4fv(uni, 1, GL_FALSE, &model_matrix[0][0]);

float *vertices = new float[18];
vertices[0] = -0.5f; vertices[1] = 0.5f; vertices[2] = 0.0f;
vertices[3] = 0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f;
vertices[6] = -0.5f; vertices[7] = -0.5f; vertices[8] = 0.0f;
vertices[0] = 0.0f; vertices[1] = 480.0f; vertices[2] = 0.0f;
vertices[3] = 640.0f; vertices[4] = 480.0f; vertices[5] = 0.0f;
vertices[6] = 0.0f; vertices[7] = 0.0f; vertices[8] = 0.0f;

vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f;
vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.0f;
vertices[15] = 0.5f; vertices[16] = 0.5f; vertices[17] = 0.0f;
vertices[9] = 640.0f; vertices[10] = 0.0f; vertices[11] = 0.0f;
vertices[12] = 0.0f; vertices[13] = 0.0f; vertices[14] = 0.0f;
vertices[15] = 640.0f; vertices[16] = 480.0f; vertices[17] = 0.0f;

const GLfloat colors[6][3] = {
{ 0.0, 0.0, 1.0 },
@@ -193,18 +210,8 @@ void Scene::Render() // XXX: rename to Blit()
glBindVertexArray(0);

#else
// XXX: debug stuff
glPushMatrix();
static float f = 0.0f;
f += 0.05f;
glTranslatef(320.0f, 240.0f, 0.0f);
glRotatef(-data->angle, 1.0f, 0.0f, 0.0f);
#if 0
glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
glRotatef(8.0f * cosf(f), 0.0f, 0.0f, 1.0f);
#endif
glTranslatef(-320.0f, -240.0f, 0.0f);
// XXX: end of debug stuff
glLoadIdentity();
glMultMatrixf(&model_matrix[0][0]);

for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2)
{
@@ -254,8 +261,6 @@ void Scene::Render() // XXX: rename to Blit()
free(vertex);
free(texture);
}

glPopMatrix();
#endif

free(data->tiles);


+ 15
- 35
src/video.cpp Voir le fichier

@@ -30,9 +30,8 @@

#if LOL_EXPERIMENTAL
Shader *stdshader;

float4x4 projection_matrix, view_matrix, model_matrix;
#endif
float4x4 projection_matrix, view_matrix, model_matrix;

#if LOL_EXPERIMENTAL
static char const *vertexshader =
@@ -91,19 +90,9 @@ void Video::Setup(int width, int height)

void Video::SetFov(float theta)
{
#if LOL_EXPERIMENTAL
float width = GetWidth();
float height = GetHeight();
//float near = -width - height;
//float far = width + height;
float near = 20.0f;
float far = 0.1f;
projection_matrix = float4x4::perspective(theta, width, height, near, far);
#else
#undef near /* Fuck Microsoft */
#undef far /* Fuck Microsoft again */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float4x4 proj;

float width = GetWidth();
float height = GetHeight();
@@ -114,7 +103,7 @@ void Video::SetFov(float theta)
if (theta < 1e-4f)
{
/* The easy way: purely orthogonal projection. */
glOrtho(0, width, 0, height, near, far);
proj = float4x4::ortho(0, width, 0, height, near, far);
}
else
{
@@ -134,10 +123,19 @@ void Video::SetFov(float theta)
near = 1.0f;
}

glFrustum(-near * t1, near * t1, -near * t2, near * t2, near, far);
glTranslatef(-0.5f * width, -0.5f * height, -dist);
proj = float4x4::frustum(-near * t1, near * t1,
-near * t2, near * t2, near, far)
* float4x4::translate(-0.5f * width, -0.5f * height, -dist);
}

#if LOL_EXPERIMENTAL
projection_matrix = proj;
view_matrix = float4x4(1.0f);
#else
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf(&proj[0][0]);

/* Reset the model view matrix, just in case */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -158,23 +156,11 @@ void Video::Clear()
glViewport(0, 0, GetWidth(), GetHeight());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

view_matrix = float4x4(1.0f);
view_matrix[3][0] = 0.0f;
view_matrix[3][1] = 0.0f;
view_matrix[3][2] = -5.0f;

model_matrix = float4x4(1.0f);
model_matrix[0][0] = 0.5f;
model_matrix[1][1] = 0.5f;
model_matrix[2][2] = 0.5f;

GLuint uni;
uni = stdshader->GetUniformLocation("projection_matrix");
glUniformMatrix4fv(uni, 1, GL_FALSE, &projection_matrix[0][0]);
uni = stdshader->GetUniformLocation("view_matrix");
glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]);
uni = stdshader->GetUniformLocation("model_matrix");
glUniformMatrix4fv(uni, 1, GL_FALSE, &model_matrix[0][0]);
#else
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
@@ -186,13 +172,7 @@ void Video::Clear()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif

#if LOL_EXPERIMENTAL
static float time;
time += 0.01f;
SetFov(1.0f + sinf(time));
#else
SetFov(0.5f);
#endif
SetFov(0.0f);
}

void Video::Destroy()


Chargement…
Annuler
Enregistrer