diff --git a/GL/draw.c b/GL/draw.c index 4c66597..8bc9e27 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -235,7 +235,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ GLboolean lighting_enabled = isLightingEnabled(); - GLushort i; + GLushort i, last_vertex; for(i = first; i < count; ++i) { pvr_vertex_t* vertex = (pvr_vertex_t*) dst; vertex->u = vertex->v = 0.0f; @@ -243,7 +243,9 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ vertex->oargb = 0; vertex->flags = PVR_CMD_VERTEX; - if(((i + 1) % elements) == 0) { + last_vertex = ((i + 1) % elements) == 0; + + if(last_vertex) { vertex->flags = PVR_CMD_VERTEX_EOL; } @@ -305,6 +307,21 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ _applyRenderMatrix(); /* Apply the Render Matrix Stack */ transformVertex(&vertex->x, &vertex->x, &vertex->y, &vertex->z); + /* The PVR doesn't support quads, only triangle strips, so we need to + * swap the last two vertices of each set */ + if(last_vertex && mode == GL_QUADS) { + /* This vertex becomes the previous vertex so store it*/ + pvr_vertex_t tmp = *vertex; + tmp.flags = PVR_CMD_VERTEX; + + /* Overwrite this vertex with the previous one, make it last */ + *vertex = *(vertex - 1); + vertex->flags = PVR_CMD_VERTEX_EOL; + + /* Now make the previous one the original last one */ + *(vertex - 1) = tmp; + } + ++dst; } } diff --git a/GL/glu.c b/GL/glu.c new file mode 100644 index 0000000..3432e95 --- /dev/null +++ b/GL/glu.c @@ -0,0 +1,15 @@ +#include +#include "private.h" + +/* Set the Perspective */ +void gluPerspective(GLfloat angle, GLfloat aspect, + GLfloat znear, GLfloat zfar) { + GLfloat xmin, xmax, ymin, ymax; + + ymax = znear * tanf(angle * F_PI / 360.0f); + ymin = -ymax; + xmin = ymin * aspect; + xmax = ymax * aspect; + + glFrustum(xmin, xmax, ymin, ymax, znear, zfar); +} diff --git a/GL/immediate.c b/GL/immediate.c index 39d28bc..d02eec1 100644 --- a/GL/immediate.c +++ b/GL/immediate.c @@ -138,6 +138,10 @@ void APIENTRY glEnd() { /* FIXME: Push pointer state */ + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, VERTICES.data); glColorPointer(4, GL_FLOAT, 0, COLOURS.data); glNormalPointer(GL_FLOAT, 0, NORMALS.data); diff --git a/Makefile b/Makefile index 8075e7a..0be6dc5 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,10 @@ link: build: $(OBJS) link -defaultall: create_kos_link $(OBJS) subdirs linklib +samples: build + $(KOS_MAKE) -C samples all + +defaultall: create_kos_link $(OBJS) subdirs linklib samples include $(KOS_BASE)/addons/Makefile.prefab diff --git a/include/glu.h b/include/glu.h index 6397441..d31f83a 100644 --- a/include/glu.h +++ b/include/glu.h @@ -23,12 +23,6 @@ __BEGIN_DECLS #define GLU_FALSE 0 #define GLU_TRUE 1 -/* Mip-Mapped Textures MUST be square or rectangle */ -GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const void *data); - /* gluPerspective - Set the Perspective for Rendering. */ GLAPI void APIENTRY gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); @@ -38,11 +32,6 @@ GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy, GLfloat upz); -/* glhLookAtf2 = gluLookAt operating on 3 float vectors. */ -GLAPI void APIENTRY glhLookAtf2(GLfloat *eyePosition3D, - GLfloat *center3D, - GLfloat *upVector3D); - GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error); __END_DECLS diff --git a/include/glut.h b/include/glut.h deleted file mode 100644 index 91e4b04..0000000 --- a/include/glut.h +++ /dev/null @@ -1,29 +0,0 @@ -/* KallistiGL for KallistiOS ##version## - - libgl/glut.h - Copyright (C) 2014 Josh Pearson - Copyright (C) 2014 Lawrence Sebald - -*/ - -#ifndef __GL_GLUT_H -#define __GL_GLUT_H - -#include -__BEGIN_DECLS - -#ifndef BUILD_LIBGL -#include -#endif - -/* Flush the Submitted Primitive Data to the GPU for render */ -GLAPI void APIENTRY glutSwapBuffers(); - -/* Copy the Submitted Primitive Data to the GPU for render to texture */ -/* This will leave the Vertex Data in the Main Buffer to be Flushed on the - next frame rendered */ -GLAPI void APIENTRY glutCopyBufferToTexture(void *dst, GLsizei *x, GLsizei *y); - -__END_DECLS - -#endif /* !__GL_GLUT_H */ diff --git a/samples/Makefile b/samples/Makefile new file mode 100644 index 0000000..bf6bd36 --- /dev/null +++ b/samples/Makefile @@ -0,0 +1,10 @@ + +# Manipulate the CFLAGS to look our *our* version of the library and includes +INC_DIR = $(abspath ../include) +LIB_DIR = $(abspath ../) +export CFLAGS := $(CFLAGS) -I $(INC_DIR) +export OBJEXTRA := $(LIB_DIR)/libGLdc.a + + +all: + $(KOS_MAKE) -C nehe02 all \ No newline at end of file diff --git a/samples/nehe02/Makefile b/samples/nehe02/Makefile new file mode 100644 index 0000000..5ba805b --- /dev/null +++ b/samples/nehe02/Makefile @@ -0,0 +1,29 @@ +TARGET = nehe02.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) diff --git a/samples/nehe02/main.c b/samples/nehe02/main.c new file mode 100644 index 0000000..1f40acb --- /dev/null +++ b/samples/nehe02/main.c @@ -0,0 +1,79 @@ +#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 + + gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window + + 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(); + + gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); + 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 + + glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0 + + // draw a triangle + glBegin(GL_POLYGON); // start drawing a polygon + glVertex3f( 0.0f, 1.0f, 0.0f); // Top + glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right + glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left + glEnd(); // we're done with the polygon + + glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units + + // draw a square (quadrilateral) + glBegin(GL_QUADS); // start drawing a polygon (4 sided) + glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left + glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right + glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right + glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left + glEnd(); // done with the polygon + + // swap buffers to display, since we're double buffered. + glKosSwapBuffers(); +} + +int main(int argc, char **argv) +{ + glKosInit(); + + InitGL(640, 480); + ReSizeGLScene(640, 480); + + while(1) { + DrawGLScene(); + } + + return 0; +} diff --git a/samples/nehe02/nehe02.elf b/samples/nehe02/nehe02.elf new file mode 100755 index 0000000..1ed585e Binary files /dev/null and b/samples/nehe02/nehe02.elf differ diff --git a/samples/nehe02/romdisk.img b/samples/nehe02/romdisk.img new file mode 100644 index 0000000..1763482 Binary files /dev/null and b/samples/nehe02/romdisk.img differ