Add gluOrtho2D, ortho2d example and fix glOrtho
This commit is contained in:
parent
101f260ce6
commit
9167869633
6
GL/glu.c
6
GL/glu.c
|
@ -2,7 +2,7 @@
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
/* Set the Perspective */
|
/* Set the Perspective */
|
||||||
void gluPerspective(GLfloat angle, GLfloat aspect,
|
void APIENTRY gluPerspective(GLfloat angle, GLfloat aspect,
|
||||||
GLfloat znear, GLfloat zfar) {
|
GLfloat znear, GLfloat zfar) {
|
||||||
GLfloat xmin, xmax, ymin, ymax;
|
GLfloat xmin, xmax, ymin, ymax;
|
||||||
|
|
||||||
|
@ -13,3 +13,7 @@ void gluPerspective(GLfloat angle, GLfloat aspect,
|
||||||
|
|
||||||
glFrustum(xmin, xmax, ymin, ymax, znear, zfar);
|
glFrustum(xmin, xmax, ymin, ymax, znear, zfar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void APIENTRY gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) {
|
||||||
|
glOrtho(left, right, bottom, top, -1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
16
GL/matrix.c
16
GL/matrix.c
|
@ -176,9 +176,9 @@ void APIENTRY glOrtho(GLfloat left, GLfloat right,
|
||||||
OrthoMatrix[3][1] = -(top + bottom) / (top - bottom);
|
OrthoMatrix[3][1] = -(top + bottom) / (top - bottom);
|
||||||
OrthoMatrix[3][2] = -(zfar + znear) / (zfar - znear);
|
OrthoMatrix[3][2] = -(zfar + znear) / (zfar - znear);
|
||||||
|
|
||||||
mat_load(stack_top(MATRIX_STACKS + MATRIX_MODE));
|
mat_load(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
mat_apply(&OrthoMatrix);
|
mat_apply(&OrthoMatrix);
|
||||||
mat_store(stack_top(MATRIX_STACKS + MATRIX_MODE));
|
mat_store(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,18 +207,6 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right,
|
||||||
mat_store(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
mat_store(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the Perspective */
|
|
||||||
void gluPerspective(GLfloat angle, GLfloat aspect,
|
|
||||||
GLfloat znear, GLfloat zfar) {
|
|
||||||
GLfloat xmin, xmax, ymin, ymax;
|
|
||||||
|
|
||||||
ymax = znear * ftan(angle * F_PI / 360.0f);
|
|
||||||
ymin = -ymax;
|
|
||||||
xmin = ymin * aspect;
|
|
||||||
xmax = ymax * aspect;
|
|
||||||
|
|
||||||
glFrustum(xmin, xmax, ymin, ymax, znear, zfar);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Multiply the current matrix by an arbitrary matrix */
|
/* Multiply the current matrix by an arbitrary matrix */
|
||||||
void glMultMatrixf(const GLfloat *m) {
|
void glMultMatrixf(const GLfloat *m) {
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@
|
||||||
# Copyright (C) 2018 Luke Benstead
|
# Copyright (C) 2018 Luke Benstead
|
||||||
|
|
||||||
TARGET = libGLdc.a
|
TARGET = libGLdc.a
|
||||||
OBJS = GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o
|
OBJS = GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o GL/glu.o
|
||||||
OBJS += GL/matrix.o GL/fog.o GL/error.o containers/stack.o containers/named_array.o containers/aligned_vector.o
|
OBJS += GL/matrix.o GL/fog.o GL/error.o containers/stack.o containers/named_array.o containers/aligned_vector.o
|
||||||
|
|
||||||
SUBDIRS =
|
SUBDIRS =
|
||||||
|
|
|
@ -23,6 +23,8 @@ __BEGIN_DECLS
|
||||||
#define GLU_FALSE 0
|
#define GLU_FALSE 0
|
||||||
#define GLU_TRUE 1
|
#define GLU_TRUE 1
|
||||||
|
|
||||||
|
GLAPI void APIENTRY gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);
|
||||||
|
|
||||||
/* gluPerspective - Set the Perspective for Rendering. */
|
/* gluPerspective - Set the Perspective for Rendering. */
|
||||||
GLAPI void APIENTRY gluPerspective(GLdouble fovy, GLdouble aspect,
|
GLAPI void APIENTRY gluPerspective(GLdouble fovy, GLdouble aspect,
|
||||||
GLdouble zNear, GLdouble zFar);
|
GLdouble zNear, GLdouble zFar);
|
||||||
|
|
|
@ -11,3 +11,4 @@ all:
|
||||||
$(KOS_MAKE) -C nehe02va all
|
$(KOS_MAKE) -C nehe02va all
|
||||||
$(KOS_MAKE) -C nehe03 all
|
$(KOS_MAKE) -C nehe03 all
|
||||||
$(KOS_MAKE) -C nehe06 all
|
$(KOS_MAKE) -C nehe06 all
|
||||||
|
$(KOS_MAKE) -C ortho2d all
|
29
samples/ortho2d/Makefile
Normal file
29
samples/ortho2d/Makefile
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
TARGET = ortho2d.elf
|
||||||
|
OBJS = main.o
|
||||||
|
|
||||||
|
all: rm-elf $(TARGET)
|
||||||
|
|
||||||
|
include $(KOS_BASE)/Makefile.rules
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f $(TARGET) $(OBJS) romdisk.*
|
||||||
|
|
||||||
|
rm-elf:
|
||||||
|
-rm -f $(TARGET) romdisk.*
|
||||||
|
|
||||||
|
$(TARGET): $(OBJS) romdisk.o
|
||||||
|
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
|
||||||
|
$(OBJS) romdisk.o $(OBJEXTRA) -lm -lkosutils $(KOS_LIBS)
|
||||||
|
|
||||||
|
romdisk.img:
|
||||||
|
$(KOS_GENROMFS) -f romdisk.img -d romdisk -v
|
||||||
|
|
||||||
|
romdisk.o: romdisk.img
|
||||||
|
$(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk.o
|
||||||
|
|
||||||
|
run: $(TARGET)
|
||||||
|
$(KOS_LOADER) $(TARGET)
|
||||||
|
|
||||||
|
dist:
|
||||||
|
rm -f $(OBJS) romdisk.o romdisk.img
|
||||||
|
$(KOS_STRIP) $(TARGET)
|
67
samples/ortho2d/main.c
Normal file
67
samples/ortho2d/main.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include "gl.h"
|
||||||
|
#include "glu.h"
|
||||||
|
#include "glkos.h"
|
||||||
|
|
||||||
|
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
||||||
|
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
|
||||||
|
{
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
|
||||||
|
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
|
||||||
|
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
|
||||||
|
//glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
||||||
|
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity(); // Reset The Projection Matrix
|
||||||
|
|
||||||
|
gluOrtho2D(0, 640, 0, 480);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */
|
||||||
|
void ReSizeGLScene(int Width, int Height)
|
||||||
|
{
|
||||||
|
if (Height == 0) // Prevent A Divide By Zero If The Window Is Too Small
|
||||||
|
Height = 1;
|
||||||
|
|
||||||
|
glViewport(0, 0, Width, Height); // Reset The Current Viewport And Perspective Transformation
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
gluOrtho2D(0, 640, 0, 480);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The main drawing function. */
|
||||||
|
void DrawGLScene()
|
||||||
|
{
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
||||||
|
glLoadIdentity(); // Reset The View
|
||||||
|
|
||||||
|
// draw a triangle
|
||||||
|
glBegin(GL_TRIANGLES); // start drawing a polygon
|
||||||
|
glVertex2f( 320.0f, 360.0f); // Top
|
||||||
|
glVertex2f( 120.0f, 120.0f);
|
||||||
|
glVertex2f( 640.0f - 120.0f, 120.0f);
|
||||||
|
glEnd(); // we're done with the polygon
|
||||||
|
|
||||||
|
glKosSwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
glKosInit();
|
||||||
|
|
||||||
|
InitGL(640, 480);
|
||||||
|
ReSizeGLScene(640, 480);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
DrawGLScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
0
samples/ortho2d/romdisk/PLACEHOLDER
Normal file
0
samples/ortho2d/romdisk/PLACEHOLDER
Normal file
Loading…
Reference in New Issue
Block a user