From 566fc8134dc3adaaa5e0d9c5671cec090e5cd7d6 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Wed, 7 Apr 2021 20:44:35 +0100 Subject: [PATCH] Add more samples --- CMakeLists.txt | 11 +++ samples/nehe02de/main.c | 6 +- samples/nehe06/main.c | 12 ++- samples/paletted/main.c | 11 +-- samples/paletted_pcx/main.c | 10 +-- samples/polygon_offset/main.c | 11 ++- samples/zclip/main.c | 129 +++++++++++++++-------------- samples/zclip_triangle/main.c | 6 +- samples/zclip_trianglestrip/main.c | 6 +- 9 files changed, 111 insertions(+), 91 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eebf8ea..9fb960f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,4 +54,15 @@ add_executable(depth_funcs_ortho samples/depth_funcs_ortho/main.c) add_executable(lights samples/lights/main.c) add_executable(mipmap samples/mipmap/main.c) add_executable(multitexture_arrays samples/multitexture_arrays/main.c samples/multitexture_arrays/pvr-texture.c) +add_executable(nehe02de samples/nehe02de/main.c) +add_executable(nehe06 samples/nehe06/main.c) +add_executable(paletted samples/paletted/main.c) +add_executable(paletted_pcx samples/paletted_pcx/main.c) +add_executable(polygon_offset samples/polygon_offset/main.c) +add_executable(zclip samples/zclip/main.c) +add_executable(zclip_triangle samples/zclip_triangle/main.c) +add_executable(zclip_trianglestrip samples/zclip_trianglestrip/main.c) +if(PLATFORM_DREAMCAST) + add_executable(polymark samples/polymark/main.c) +endif() diff --git a/samples/nehe02de/main.c b/samples/nehe02de/main.c index eba7fca..f84775c 100644 --- a/samples/nehe02de/main.c +++ b/samples/nehe02de/main.c @@ -1,6 +1,6 @@ -#include "gl.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/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. diff --git a/samples/nehe06/main.c b/samples/nehe06/main.c index cd3e9f1..39570c2 100644 --- a/samples/nehe06/main.c +++ b/samples/nehe06/main.c @@ -1,10 +1,14 @@ #include +#include +#include +#include -#include "gl.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/glext.h" +#include "GL/glkos.h" -extern uint8 romdisk[]; +extern uint8_t romdisk[]; KOS_INIT_ROMDISK(romdisk); /* floats for x rotation, y rotation, z rotation */ diff --git a/samples/paletted/main.c b/samples/paletted/main.c index 5def756..69826da 100644 --- a/samples/paletted/main.c +++ b/samples/paletted/main.c @@ -1,13 +1,14 @@ #include #include #include +#include -#include "gl.h" -#include "glext.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glext.h" +#include "GL/glu.h" +#include "GL/glkos.h" -extern uint8 romdisk[]; +extern uint8_t romdisk[]; KOS_INIT_ROMDISK(romdisk); /* floats for x rotation, y rotation, z rotation */ diff --git a/samples/paletted_pcx/main.c b/samples/paletted_pcx/main.c index b82a54a..354f990 100644 --- a/samples/paletted_pcx/main.c +++ b/samples/paletted_pcx/main.c @@ -4,12 +4,12 @@ #include #include -#include "gl.h" -#include "glext.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/glext.h" +#include "GL/glkos.h" -extern uint8 romdisk[]; +extern uint8_t romdisk[]; KOS_INIT_ROMDISK(romdisk); /* floats for x rotation, y rotation, z rotation */ diff --git a/samples/polygon_offset/main.c b/samples/polygon_offset/main.c index 101f4d6..5c46165 100644 --- a/samples/polygon_offset/main.c +++ b/samples/polygon_offset/main.c @@ -1,12 +1,13 @@ -#include + typedef enum { false, true } bool; -#include "gl.h" -#include "glu.h" -#include "glkos.h" + +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/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. @@ -96,6 +97,7 @@ void drawPolygon() int frames = 0; void check_input() { +#ifdef __DREAMCAST__ maple_device_t *cont; cont_state_t *state; @@ -117,6 +119,7 @@ void check_input() } } } +#endif } /* The main drawing function. */ diff --git a/samples/zclip/main.c b/samples/zclip/main.c index cbe2148..c4acccf 100644 --- a/samples/zclip/main.c +++ b/samples/zclip/main.c @@ -1,13 +1,14 @@ #include #include #include +#include -#include "gl.h" -#include "glext.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/glext.h" +#include "GL/glkos.h" -extern uint8 romdisk[]; +extern uint8_t romdisk[]; KOS_INIT_ROMDISK(romdisk); @@ -29,85 +30,85 @@ TextureImage lightmap; GLboolean LoadTGA(TextureImage *texture, const char *filename) // Loads A TGA File Into Memory { - GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header - GLubyte TGAcompare[12]; // Used To Compare TGA Header - GLubyte header[6]; // First 6 Useful Bytes From The Header - GLuint bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The TGA File - GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram - GLuint temp; // Temporary Variable - GLuint type=GL_RGBA; // Set The Default GL Mode To RBGA (32 BPP) + GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header + GLubyte TGAcompare[12]; // Used To Compare TGA Header + GLubyte header[6]; // First 6 Useful Bytes From The Header + GLuint bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The TGA File + GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram + GLuint temp; // Temporary Variable + GLuint type=GL_RGBA; // Set The Default GL Mode To RBGA (32 BPP) - FILE *file = fopen(filename, "rb"); // Open The TGA File + FILE *file = fopen(filename, "rb"); // Open The TGA File - if( file==NULL || // Does File Even Exist? - fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || // Are There 12 Bytes To Read? - memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want? - fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes - { - if (file == NULL) { // Did The File Even Exist? *Added Jim Strong* + if( file==NULL || // Does File Even Exist? + fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || // Are There 12 Bytes To Read? + memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want? + fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes + { + if (file == NULL) { // Did The File Even Exist? *Added Jim Strong* fprintf(stderr, "Missing file\n"); - return GL_FALSE; // Return False + return GL_FALSE; // Return False } else - { + { fprintf(stderr, "Invalid format\n"); - fclose(file); // If Anything Failed, Close The File - return GL_FALSE; // Return False - } - } + fclose(file); // If Anything Failed, Close The File + return GL_FALSE; // Return False + } + } - texture->width = header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte) - texture->height = header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte) + texture->width = header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte) + texture->height = header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte) - if( texture->width <=0 || // Is The Width Less Than Or Equal To Zero - texture->height <=0 || // Is The Height Less Than Or Equal To Zero - (header[4]!=24 && header[4]!=32)) // Is The TGA 24 or 32 Bit? - { - fprintf(stderr, "Wrong format\n"); + if( texture->width <=0 || // Is The Width Less Than Or Equal To Zero + texture->height <=0 || // Is The Height Less Than Or Equal To Zero + (header[4]!=24 && header[4]!=32)) // Is The TGA 24 or 32 Bit? + { + fprintf(stderr, "Wrong format\n"); fclose(file); // If Anything Failed, Close The File - return GL_FALSE; // Return False - } + return GL_FALSE; // Return False + } - texture->bpp = header[4]; // Grab The TGA's Bits Per Pixel (24 or 32) - bytesPerPixel = texture->bpp/8; // Divide By 8 To Get The Bytes Per Pixel - imageSize = texture->width*texture->height*bytesPerPixel; // Calculate The Memory Required For The TGA Data + texture->bpp = header[4]; // Grab The TGA's Bits Per Pixel (24 or 32) + bytesPerPixel = texture->bpp/8; // Divide By 8 To Get The Bytes Per Pixel + imageSize = texture->width*texture->height*bytesPerPixel; // Calculate The Memory Required For The TGA Data - texture->imageData=(GLubyte *)malloc(imageSize); // Reserve Memory To Hold The TGA Data + texture->imageData=(GLubyte *)malloc(imageSize); // Reserve Memory To Hold The TGA Data - if( texture->imageData==NULL || // Does The Storage Memory Exist? - fread(texture->imageData, 1, imageSize, file)!=imageSize) // Does The Image Size Match The Memory Reserved? - { - if(texture->imageData!=NULL) // Was Image Data Loaded - free(texture->imageData); // If So, Release The Image Data + if( texture->imageData==NULL || // Does The Storage Memory Exist? + fread(texture->imageData, 1, imageSize, file)!=imageSize) // Does The Image Size Match The Memory Reserved? + { + if(texture->imageData!=NULL) // Was Image Data Loaded + free(texture->imageData); // If So, Release The Image Data - fclose(file); // Close The File - return GL_FALSE; // Return False - } + fclose(file); // Close The File + return GL_FALSE; // Return False + } GLuint i; - for(i = 0; i < (int)imageSize; i += bytesPerPixel) // Loop Through The Image Data - { // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue) - temp=texture->imageData[i]; // Temporarily Store The Value At Image Data 'i' - texture->imageData[i] = texture->imageData[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte - texture->imageData[i + 2] = temp; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value) - } + for(i = 0; i < (int)imageSize; i += bytesPerPixel) // Loop Through The Image Data + { // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue) + temp=texture->imageData[i]; // Temporarily Store The Value At Image Data 'i' + texture->imageData[i] = texture->imageData[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte + texture->imageData[i + 2] = temp; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value) + } - fclose (file); // Close The File + fclose (file); // Close The File - // Build A Texture From The Data - glGenTextures(1, &texture[0].texID); // Generate OpenGL texture IDs + // Build A Texture From The Data + glGenTextures(1, &texture[0].texID); // Generate OpenGL texture IDs - glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered + glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered - if (texture[0].bpp==24) // Was The TGA 24 Bits - { - type=GL_RGB; // If So Set The 'type' To GL_RGB - } + if (texture[0].bpp==24) // Was The TGA 24 Bits + { + type=GL_RGB; // If So Set The 'type' To GL_RGB + } - glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData); + glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData); - return GL_TRUE; // Texture Building Went Ok, Return True + return GL_TRUE; // Texture Building Went Ok, Return True } // Load Bitmaps And Convert To Textures void LoadGLTextures() { diff --git a/samples/zclip_triangle/main.c b/samples/zclip_triangle/main.c index 46ea274..0400f0b 100644 --- a/samples/zclip_triangle/main.c +++ b/samples/zclip_triangle/main.c @@ -2,9 +2,9 @@ #include #include -#include "gl.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/glkos.h" /* A general OpenGL initialization function. Sets all of the initial parameters. */ diff --git a/samples/zclip_trianglestrip/main.c b/samples/zclip_trianglestrip/main.c index f6b8e80..332ec3e 100644 --- a/samples/zclip_trianglestrip/main.c +++ b/samples/zclip_trianglestrip/main.c @@ -2,9 +2,9 @@ #include #include -#include "gl.h" -#include "glu.h" -#include "glkos.h" +#include "GL/gl.h" +#include "GL/glu.h" +#include "GL/glkos.h" /* A general OpenGL initialization function. Sets all of the initial parameters. */