Add the first nehe sample and make it work
This commit is contained in:
parent
f9809ec2b7
commit
b6b1591010
21
GL/draw.c
21
GL/draw.c
|
@ -235,7 +235,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ
|
||||||
|
|
||||||
GLboolean lighting_enabled = isLightingEnabled();
|
GLboolean lighting_enabled = isLightingEnabled();
|
||||||
|
|
||||||
GLushort i;
|
GLushort i, last_vertex;
|
||||||
for(i = first; i < count; ++i) {
|
for(i = first; i < count; ++i) {
|
||||||
pvr_vertex_t* vertex = (pvr_vertex_t*) dst;
|
pvr_vertex_t* vertex = (pvr_vertex_t*) dst;
|
||||||
vertex->u = vertex->v = 0.0f;
|
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->oargb = 0;
|
||||||
vertex->flags = PVR_CMD_VERTEX;
|
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;
|
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 */
|
_applyRenderMatrix(); /* Apply the Render Matrix Stack */
|
||||||
transformVertex(&vertex->x, &vertex->x, &vertex->y, &vertex->z);
|
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;
|
++dst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
GL/glu.c
Normal file
15
GL/glu.c
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <math.h>
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -138,6 +138,10 @@ void APIENTRY glEnd() {
|
||||||
|
|
||||||
/* FIXME: Push pointer state */
|
/* FIXME: Push pointer state */
|
||||||
|
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
glVertexPointer(3, GL_FLOAT, 0, VERTICES.data);
|
glVertexPointer(3, GL_FLOAT, 0, VERTICES.data);
|
||||||
glColorPointer(4, GL_FLOAT, 0, COLOURS.data);
|
glColorPointer(4, GL_FLOAT, 0, COLOURS.data);
|
||||||
glNormalPointer(GL_FLOAT, 0, NORMALS.data);
|
glNormalPointer(GL_FLOAT, 0, NORMALS.data);
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -19,7 +19,10 @@ link:
|
||||||
build: $(OBJS) 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
|
include $(KOS_BASE)/addons/Makefile.prefab
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,6 @@ __BEGIN_DECLS
|
||||||
#define GLU_FALSE 0
|
#define GLU_FALSE 0
|
||||||
#define GLU_TRUE 1
|
#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. */
|
/* 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);
|
||||||
|
@ -38,11 +32,6 @@ GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
|
||||||
GLfloat centerx, GLfloat centery, GLfloat centerz,
|
GLfloat centerx, GLfloat centery, GLfloat centerz,
|
||||||
GLfloat upx, GLfloat upy, GLfloat upz);
|
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);
|
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error);
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
|
@ -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 <sys/cdefs.h>
|
|
||||||
__BEGIN_DECLS
|
|
||||||
|
|
||||||
#ifndef BUILD_LIBGL
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#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 */
|
|
10
samples/Makefile
Normal file
10
samples/Makefile
Normal file
|
@ -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
|
29
samples/nehe02/Makefile
Normal file
29
samples/nehe02/Makefile
Normal file
|
@ -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)
|
79
samples/nehe02/main.c
Normal file
79
samples/nehe02/main.c
Normal file
|
@ -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;
|
||||||
|
}
|
BIN
samples/nehe02/nehe02.elf
Executable file
BIN
samples/nehe02/nehe02.elf
Executable file
Binary file not shown.
BIN
samples/nehe02/romdisk.img
Normal file
BIN
samples/nehe02/romdisk.img
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user