Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static SDL_Surface *scr;
#define P(m, y, x) (m->data[y][x])

MATRIX *transformation;
static GLProjectionMode projection_mode = GLProjectionMode::GL_PROJECTION_PERSPECTIVE; //Default mode is perspective
static COLOR color;
static GLFix u, v;
static COLOR *screen;
Expand All @@ -27,8 +28,10 @@ static const TEXTURE *texture;
static unsigned int vertices_count = 0;
static VERTEX vertices[4];
static GLDrawMode draw_mode = GL_TRIANGLES;
static bool is_monochrome;
static COLOR *screen_inverted; //For monochrome calcs
#ifdef _TINSPIRE
static bool is_monochrome;
static COLOR *screen_inverted; //For monochrome calcs
#endif
#ifdef FPS_COUNTER
volatile unsigned int fps;
#endif
Expand Down Expand Up @@ -74,10 +77,9 @@ void nglUninit()
uninit_fastmath();
delete[] transformation;
delete[] z_buffer;

delete[] screen_inverted;


#ifdef _TINSPIRE
delete[] screen_inverted;
lcd_init(SCR_TYPE_INVALID);
#else
//TODO
Expand Down Expand Up @@ -133,8 +135,16 @@ void nglMultMatVectRes(const MATRIX *mat1, const VECTOR3 *vect, VECTOR3 *res)
res->z = P(mat1, 2, 0)*x + P(mat1, 2, 1)*y + P(mat1, 2, 2)*z + P(mat1, 2, 3);
}

void nglSetProjectionMode(GLProjectionMode mode)
{
projection_mode = mode;
}

void nglPerspective(VERTEX *v)
{
if (projection_mode == GL_PROJECTION_ORTHOGRAPHIC)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is the right place. Arguably the projection should only be applied to actual drawing, not when calling nglPerspective manually? Not sure about use cases.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It felt less verbose than adding it to every usage of nglPerspective().

return; //Ortho mode
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs blank line after this


#ifdef BETTER_PERSPECTIVE
float new_z = v->z;
decltype(new_z) new_x = v->x, new_y = v->y;
Expand Down Expand Up @@ -188,6 +198,9 @@ void nglPerspective(VERTEX *v)

void nglPerspective(VECTOR3 *v)
{
if (projection_mode == GL_PROJECTION_ORTHOGRAPHIC)
Comment thread
tobleroneaddict marked this conversation as resolved.
return; //Ortho mode

#ifdef BETTER_PERSPECTIVE
float new_z = v->z;
decltype(new_z) new_x = v->x, new_y = v->y;
Expand Down
7 changes: 7 additions & 0 deletions gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ class MATRIX {
#define GL_COLOR_BUFFER_BIT 1<<0
#define GL_DEPTH_BUFFER_BIT 1<<1

enum GLProjectionMode
{
GL_PROJECTION_PERSPECTIVE,
GL_PROJECTION_ORTHOGRAPHIC
};

enum GLDrawMode
{
GL_TRIANGLES,
Expand Down Expand Up @@ -162,6 +168,7 @@ void nglDrawTriangleZClipped(const VERTEX *low, const VERTEX *middle, const VERT
void nglInterpolateVertexZ(const VERTEX *from, const VERTEX *to, VERTEX *res);
void nglDrawLine3D(const VERTEX *v1, const VERTEX *v2);

void nglSetProjectionMode(GLProjectionMode mode);
void nglPerspective(VERTEX *v);
void nglPerspective(VECTOR3 *v);
void nglMultMatVectRes(const MATRIX *mat1, const VERTEX *vect, VERTEX *res);
Expand Down