mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:57:45 +00:00
LibGL: Implement glOrtho and underlying functions
This commit is contained in:
parent
f07a7f7b94
commit
f601f12801
5 changed files with 43 additions and 0 deletions
|
@ -81,6 +81,7 @@ GLAPI GLubyte* glGetString(GLenum name);
|
|||
GLAPI void glLoadIdentity();
|
||||
GLAPI void glLoadMatrixf(const GLfloat* matrix);
|
||||
GLAPI void glMatrixMode(GLenum mode);
|
||||
GLAPI void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);
|
||||
GLAPI void glPushMatrix();
|
||||
GLAPI void glPopMatrix();
|
||||
GLAPI void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
virtual void gl_load_identity() = 0;
|
||||
virtual void gl_load_matrix(const FloatMatrix4x4& matrix) = 0;
|
||||
virtual void gl_matrix_mode(GLenum mode) = 0;
|
||||
virtual void gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) = 0;
|
||||
virtual void gl_push_matrix() = 0;
|
||||
virtual void gl_pop_matrix() = 0;
|
||||
virtual void gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) = 0;
|
||||
|
|
|
@ -65,3 +65,8 @@ void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLd
|
|||
{
|
||||
g_gl_context->gl_frustum(left, right, bottom, top, nearVal, farVal);
|
||||
}
|
||||
|
||||
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)
|
||||
{
|
||||
g_gl_context->gl_ortho(left, right, bottom, top, nearVal, farVal);
|
||||
}
|
||||
|
|
|
@ -445,6 +445,41 @@ void SoftwareGLContext::gl_frustum(GLdouble left, GLdouble right, GLdouble botto
|
|||
m_error = GL_NO_ERROR;
|
||||
}
|
||||
|
||||
void SoftwareGLContext::gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val)
|
||||
{
|
||||
if (m_in_draw_state) {
|
||||
m_error = GL_INVALID_OPERATION;
|
||||
return;
|
||||
}
|
||||
|
||||
if (left == right || bottom == top || near_val == far_val) {
|
||||
m_error = GL_INVALID_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
auto rl = right - left;
|
||||
auto tb = top - bottom;
|
||||
auto fn = far_val - near_val;
|
||||
auto tx = -(right + left) / rl;
|
||||
auto ty = -(top + bottom) / tb;
|
||||
auto tz = -(far_val + near_val) / fn;
|
||||
|
||||
FloatMatrix4x4 projection {
|
||||
static_cast<float>(2 / rl), 0, 0, static_cast<float>(tx),
|
||||
0, static_cast<float>(2 / tb), 0, static_cast<float>(ty),
|
||||
0, 0, static_cast<float>(-2 / fn), static_cast<float>(tz),
|
||||
0, 0, 0, 1
|
||||
};
|
||||
|
||||
if (m_current_matrix_mode == GL_PROJECTION) {
|
||||
m_projection_matrix = m_projection_matrix * projection;
|
||||
} else if (m_current_matrix_mode == GL_MODELVIEW) {
|
||||
m_projection_matrix = m_model_view_matrix * projection;
|
||||
}
|
||||
|
||||
m_error = GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum SoftwareGLContext::gl_get_error()
|
||||
{
|
||||
if (m_in_draw_state) {
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
virtual void gl_load_identity() override;
|
||||
virtual void gl_load_matrix(const FloatMatrix4x4& matrix) override;
|
||||
virtual void gl_matrix_mode(GLenum mode) override;
|
||||
virtual void gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) override;
|
||||
virtual void gl_push_matrix() override;
|
||||
virtual void gl_pop_matrix() override;
|
||||
virtual void gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue