_w = w;
_h = h;
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, _w, _h);
gl_offscreenReshape(_w, _h);
glutPostRedisplay();
// Set up projection matrix
glMatrixMode(GL_PROJECTION); // Select projection matrix
- glLoadIdentity(); // Start with an identity matrix
+ c3mat4 p = perspective3D(50, (float)_w / (float)_h, z_min, z_max);
+ glLoadMatrixf(p.n);
- gluPerspective(50, (float)_w / (float)_h, z_min, z_max);
#if 0
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Type Of Blending To Use
glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glMultMatrixf(c3context_view_get(c3)->cam.mtx.n);
- glTranslatef(-c3context_view_get(c3)->cam.eye.n[VX],
- -c3context_view_get(c3)->cam.eye.n[VY],
- -c3context_view_get(c3)->cam.eye.n[VZ]);
-
- dumpError("flush");
c3context_draw(c3);
glScalef(1, -1, 1);
glTranslatef(0, -1 * _h, 0);
glMatrixMode(GL_MODELVIEW); // Select modelview matrix
- glLoadIdentity(); // Start with an identity matrix
if (hud)
c3context_draw(hud);
C3_DRIVER(g->object->context, geometry_dispose, g);
str_free(g->name);
c3vertex_array_free(&g->vertice);
- c3vertex_array_free(&g->projected);
c3tex_array_free(&g->textures);
c3colorf_array_free(&g->colorf);
free(g);
c3mat4p m)
{
if (g->vertice.count) {
- c3vertex_array_realloc(&g->projected, g->vertice.count);
- g->projected.count = g->vertice.count;
for (int vi = 0; vi < g->vertice.count; vi++) {
- g->projected.e[vi] = c3mat4_mulv3(m, g->vertice.e[vi]);
+ c3vec3 v = c3mat4_mulv3(m, g->vertice.e[vi]);
if (vi == 0)
- g->bbox.min = g->bbox.max = g->projected.e[vi];
+ g->bbox.min = g->bbox.max = v;
else {
- g->bbox.max = c3vec3_min(g->bbox.min, g->projected.e[vi]);
- g->bbox.max = c3vec3_max(g->bbox.max, g->projected.e[vi]);
+ g->bbox.max = c3vec3_min(g->bbox.min, v);
+ g->bbox.max = c3vec3_max(g->bbox.max, v);
}
}
- }
+ } else
+ g->bbox.min = g->bbox.max = c3vec3f(0,0,0);
if (g->object && g->object->context)
C3_DRIVER(g->object->context, geometry_project, g, m);
* real format of the vertices. like GL_LINES etc
*/
typedef struct c3geometry_type_t {
- uint32_t type;
- c3apiobject_t subtype;
+ uint32_t type; // C3_RAW_TYPE etc
+ c3apiobject_t subtype; // GL_LINES etc
} c3geometry_type_t;
/*!
* c3object that has the projection
*/
typedef struct c3geometry_t {
- c3geometry_type_t type; // C3_TRIANGLE_TYPE, GL_LINES etc
+ c3geometry_type_t type; // geometry type
int dirty : 1,
custom : 1; // has a custom driver
str_p name; // optional
+ c3apiobject_t bid; // buffer id for opengl
+
c3material_t mat;
- struct c3object_t * object;
+ struct c3object_t * object; // parent object
const struct c3driver_geometry_t ** driver;
+ c3bbox_t bbox; // world aligned bounding box
c3vertex_array_t vertice;
- c3tex_array_t textures;
- c3colorf_array_t colorf;
- c3vertex_array_t normals;
- c3indices_array_t indices;
-
- // projected version of the vertice
- c3vertex_array_t projected;
- c3bbox_t bbox;
+ c3tex_array_t textures; // optional: texture coordinates
+ c3vertex_array_t normals; // optional: vertex normals
+ c3indices_array_t indices; // optional: vertex indices
+ // could go ?
+ c3colorf_array_t colorf; // optional: vertex colors
/*
* Some shared attributes
const c3driver_object_t * d,
c3mat4p m)
{
+ o->world = *m;
if (!o->dirty)
return;
-
-// c3mat4 identity = identity3D();
c3mat4 p = *m;
for (int pi = 0; pi < o->transform.count; pi++)
p = c3mat4_mul(&p, &o->transform.e[pi]->matrix);
-// bool is_identity = c3mat4_equal(m, &identity);
o->world = p;
for (int gi = 0; gi < o->geometry.count; gi++) {
c3geometry_p g = o->geometry.e[gi];
- c3vertex_array_clear(&g->projected);
-
- g->bbox.min = g->bbox.max = c3vec3f(0,0,0);
c3geometry_project(g, &p);
}
for (int oi = 0; oi < o->objects.count; oi++)
glColor4fv(g->mat.color.n);
dumpError("glColor");
// glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, g->mat.color.n);
- glVertexPointer(3, GL_FLOAT, 0,
- g->projected.count ? g->projected.e : g->vertice.e);
+ glVertexPointer(3, GL_FLOAT, 0, g->vertice.e);
glEnableClientState(GL_VERTEX_ARRAY);
dumpError("GL_VERTEX_ARRAY");
+
+ c3mat4 eye = c3mat4_mul(
+ &g->object->world,
+ &c3context_view_get(g->object->context)->cam.mtx);
+ glLoadMatrixf(eye.n);
+
glDisable(GL_TEXTURE_2D);
if (g->mat.texture) {
GLuint mode = g->mat.texture->normalize ?
glEnableClientState(GL_NORMAL_ARRAY);
}
if (g->indices.count) {
- // GLCHECK(glIndexPointer(GL_UNSIGNED_SHORT, 0, g->indices.e));
- // glEnableClientState(GL_INDEX_ARRAY);
GLCHECK(glDrawElements((GLuint)g->type.subtype,
g->indices.count, GL_UNSIGNED_SHORT,
g->indices.e));
- // glDisableClientState(GL_INDEX_ARRAY);
} else {
- glDrawArrays((GLuint)g->type.subtype, 0,
- g->projected.count ? g->projected.count : g->vertice.count);
+ glDrawArrays((GLuint)g->type.subtype, 0, g->vertice.count);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);