From: ljsebald <ljs...@us...> - 2023-12-29 20:36:04
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 72590d1643c42950485ede92db461964c3e3a0bc (commit) from 7094ca6e7f15a31e0aefc111ce3c16c8b784bd38 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 72590d1643c42950485ede92db461964c3e3a0bc Author: Andy Barajas <and...@gm...> Date: Fri Dec 29 12:35:35 2023 -0800 Add some gldc examples (#435) ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/gldc/basic/Makefile | 2 +- examples/dreamcast/{kgl => gldc}/basic/gl/Makefile | 2 +- examples/dreamcast/{kgl => gldc}/basic/gl/gltest.c | 21 ++- examples/dreamcast/gldc/basic/gl/pvr-texture.c | 176 +++++++++++++++++++++ .../gltest => gldc/basic/gl}/romdisk/glass.pvr | Bin examples/dreamcast/gldc/nehe/Makefile | 2 +- .../dreamcast/{kgl => gldc}/nehe/nehe06/Makefile | 4 +- .../dreamcast/{kgl => gldc}/nehe/nehe06/nehe06.c | 8 +- examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c | 176 +++++++++++++++++++++ .../gltest => gldc/nehe/nehe06}/romdisk/glass.pvr | Bin .../dreamcast/{kgl => gldc}/nehe/nehe08/Makefile | 2 +- .../dreamcast/{kgl => gldc}/nehe/nehe08/nehe08.c | 14 +- examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c | 176 +++++++++++++++++++++ .../gltest => gldc/nehe/nehe08}/romdisk/glass.pvr | Bin .../dreamcast/{kgl => gldc}/nehe/nehe09/Makefile | 2 +- .../dreamcast/{kgl => gldc}/nehe/nehe09/nehe09.c | 8 +- examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c | 176 +++++++++++++++++++++ .../{kgl => gldc}/nehe/nehe09/romdisk/star.pvr | Bin .../dreamcast/{kgl => gldc}/nehe/nehe16/Makefile | 2 +- .../dreamcast/{kgl => gldc}/nehe/nehe16/nehe16.c | 11 +- examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c | 176 +++++++++++++++++++++ .../gltest => gldc/nehe/nehe16}/romdisk/glass.pvr | Bin 22 files changed, 923 insertions(+), 35 deletions(-) copy examples/dreamcast/{kgl => gldc}/basic/gl/Makefile (88%) copy examples/dreamcast/{kgl => gldc}/basic/gl/gltest.c (91%) create mode 100644 examples/dreamcast/gldc/basic/gl/pvr-texture.c copy examples/dreamcast/{cpp/gltest => gldc/basic/gl}/romdisk/glass.pvr (100%) mode change 100755 => 100644 copy examples/dreamcast/{kgl => gldc}/nehe/nehe06/Makefile (87%) copy examples/dreamcast/{kgl => gldc}/nehe/nehe06/nehe06.c (97%) create mode 100644 examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c copy examples/dreamcast/{cpp/gltest => gldc/nehe/nehe06}/romdisk/glass.pvr (100%) mode change 100755 => 100644 copy examples/dreamcast/{kgl => gldc}/nehe/nehe08/Makefile (88%) copy examples/dreamcast/{kgl => gldc}/nehe/nehe08/nehe08.c (93%) create mode 100644 examples/dreamcast/gldc/nehe/nehe08/pvr-texture.c copy examples/dreamcast/{cpp/gltest => gldc/nehe/nehe08}/romdisk/glass.pvr (100%) mode change 100755 => 100644 copy examples/dreamcast/{kgl => gldc}/nehe/nehe09/Makefile (88%) copy examples/dreamcast/{kgl => gldc}/nehe/nehe09/nehe09.c (98%) create mode 100644 examples/dreamcast/gldc/nehe/nehe09/pvr-texture.c copy examples/dreamcast/{kgl => gldc}/nehe/nehe09/romdisk/star.pvr (100%) copy examples/dreamcast/{kgl => gldc}/nehe/nehe16/Makefile (88%) copy examples/dreamcast/{kgl => gldc}/nehe/nehe16/nehe16.c (96%) create mode 100644 examples/dreamcast/gldc/nehe/nehe16/pvr-texture.c copy examples/dreamcast/{cpp/gltest => gldc/nehe/nehe16}/romdisk/glass.pvr (100%) mode change 100755 => 100644 diff --git a/examples/dreamcast/gldc/basic/Makefile b/examples/dreamcast/gldc/basic/Makefile index 5e6a058..dc91493 100644 --- a/examples/dreamcast/gldc/basic/Makefile +++ b/examples/dreamcast/gldc/basic/Makefile @@ -8,7 +8,7 @@ # This will make all the examples, leaving only the elf files. # If you want to clean everything, use 'clean'. -SUBDIRS = vq +SUBDIRS = vq gl all: $(patsubst %, _dir_%, $(SUBDIRS)) diff --git a/examples/dreamcast/kgl/basic/gl/Makefile b/examples/dreamcast/gldc/basic/gl/Makefile similarity index 88% copy from examples/dreamcast/kgl/basic/gl/Makefile copy to examples/dreamcast/gldc/basic/gl/Makefile index 5ffcfa1..c223d07 100644 --- a/examples/dreamcast/kgl/basic/gl/Makefile +++ b/examples/dreamcast/gldc/basic/gl/Makefile @@ -19,7 +19,7 @@ rm-elf: -rm -f $(TARGET) romdisk.* $(TARGET): $(OBJS) - kos-cc -o $(TARGET) $(OBJS) -lKGL -lpcx -lkosutils + kos-cc -o $(TARGET) $(OBJS) -lGL -lm -lpcx -lkosutils run: $(TARGET) $(KOS_LOADER) $(TARGET) diff --git a/examples/dreamcast/kgl/basic/gl/gltest.c b/examples/dreamcast/gldc/basic/gl/gltest.c similarity index 91% copy from examples/dreamcast/kgl/basic/gl/gltest.c copy to examples/dreamcast/gldc/basic/gl/gltest.c index 17f9bdc..7585f3c 100644 --- a/examples/dreamcast/kgl/basic/gl/gltest.c +++ b/examples/dreamcast/gldc/basic/gl/gltest.c @@ -8,9 +8,9 @@ #include <kos.h> -#include <KGL/gl.h> -#include <KGL/glu.h> -#include <KGL/glut.h> +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glkos.h> /* @@ -26,7 +26,7 @@ Thanks to NeHe's tutorials for the texture. This example demonstrates some of the differences between KGL and OpenGL. Notice how we actually call glEnable(GL_BLEND) to enable transparency. -This remains in effect until we call glDisable(GL_BLEND). +This remains in effect untill we call glDisable(GL_BLEND). In OpenGL, there is no glKosFinishList() like in KGL. Also, in OpenGL we call glutSwapBuffers() to flush the vertices to the GPU. @@ -139,8 +139,9 @@ int main(int argc, char **argv) { /* Load a texture */ glTextureLoadPVR("/rd/glass.pvr", 0, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glClearColor(0.3f, 0.4f, 0.5f, 1.0f); @@ -200,6 +201,10 @@ int main(int argc, char **argv) { glRotatef(r, 0.0f, 1.0f, 0.5f); glPushMatrix(); + /* Always draw 2 cubes as solids */ + glEnable(GL_CULL_FACE); + glDisable(GL_BLEND); + glTranslatef(-5.0f, 0.0f, 0.0f); cube(r); @@ -231,12 +236,12 @@ int main(int argc, char **argv) { } /* Finish the frame */ - glutSwapBuffers(); + glKosSwapBuffers(); } pvr_get_stats(&stats); printf("VBL Count: %ld, last_time: %d, frame rate: %f fps\n", - stats.vbl_count, stats.frame_last_time, (double)stats.frame_rate); + stats.vbl_count, stats.frame_last_time, stats.frame_rate); return 0; } diff --git a/examples/dreamcast/gldc/basic/gl/pvr-texture.c b/examples/dreamcast/gldc/basic/gl/pvr-texture.c new file mode 100644 index 0000000..00592c3 --- /dev/null +++ b/examples/dreamcast/gldc/basic/gl/pvr-texture.c @@ -0,0 +1,176 @@ +/* + KallistiOS 2.0.0 + + pvr-texture.c + (c)2014 Josh PH3NOM Pearson + + Load A PVR Texture to the PVR using Open GL +*/ +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> + +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glkos.h> +#include <GL/glext.h> + +#define PVR_HDR_SIZE 0x20 +#define MAX(x, y) ((x > y) ? x : y) + +static GLuint PVR_TextureHeight(unsigned char *HDR); +static GLuint PVR_TextureWidth(unsigned char *HDR); +static GLuint PVR_TextureFormat(unsigned char *HDR); + +static GLuint _glGetMipmapLevelCount(GLuint width, GLuint height) { + return 1 + floor(log2(MAX(width, height))); +} + +static GLuint _glGetMipmapDataSize(GLuint width, GLuint height) { + GLuint size = 0; + + GLuint i = 0; + + for(; i < _glGetMipmapLevelCount(width, height); ++i) { + size += (width * height * 2); + + if(width > 1) { + width /= 2; + } + + if(height > 1) { + height /= 2; + } + } + + return size; +} + +/* Load a PVR texture file into memory, and then bind the texture to Open GL. + fname is the name of the PVR texture file to be opened and read. + isMipMapped should be passed as 1 if the texture contains MipMap levels, 0 otherwise. + glMipMap should be passed as 1 if Open GL should calculate the Mipmap levels, 0 otherwise */ +GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char glMipMap) { + FILE *tex = NULL; + uint16_t *TEX0 = NULL; + uint8_t HDR[PVR_HDR_SIZE]; + GLuint texID, texSize, texW, texH, texFormat; + + /* Open the PVR texture file, and get its file size */ + tex = fopen(fname, "rb"); + + if(tex == NULL) { + printf("FILE READ ERROR: %s\n", fname); + + while(1); + } + + fseek(tex, 0, SEEK_END); + texSize = ftell(tex) - PVR_HDR_SIZE; + fseek(tex, 0, SEEK_SET); + + /* Read in the PVR texture file header */ + fread(HDR, 1, PVR_HDR_SIZE, tex); + + /* Extract some information from the PVR texture file header */ + texW = PVR_TextureWidth(HDR); + texH = PVR_TextureHeight(HDR); + texFormat = PVR_TextureFormat(HDR); + + /* Allocate Some Memory for the texture. If we are using Open GL to build the MipMap, + we need to allocate enough space to hold the MipMap texture levels. */ + if(!isMipMapped && glMipMap) + TEX0 = malloc(_glGetMipmapDataSize(texW, texH)); + else + TEX0 = malloc(texSize); + + fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */ + + /* Generate and bind a texture as normal for Open GL */ + glGenTextures(1, &texID); + glBindTexture(GL_TEXTURE_2D, texID); + + if(texFormat != GL_UNSIGNED_SHORT_5_6_5) + glCompressedTexImage2D(GL_TEXTURE_2D, + 0, + texFormat, + texW, + texH, + 0, + texSize, + TEX0); + else { + //fprintf(stderr, "%x\n", texFormat); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + texW, texH, + 0, + GL_RGB, + texFormat, + TEX0); + if(!isMipMapped && glMipMap) + glGenerateMipmapEXT(GL_TEXTURE_2D); + } + + free(TEX0); + + return texID; +} + +static GLuint PVR_TextureFormat(unsigned char *HDR) { + GLuint color = (GLuint)HDR[PVR_HDR_SIZE - 8]; + GLuint format = (GLuint)HDR[PVR_HDR_SIZE - 7]; + + GLboolean twiddled = format == 0x01; + GLboolean compressed = (format == 0x10 || format == 0x03); + + if(compressed) { + if(twiddled) { + switch(color) { + case 0x0: { + return GL_COMPRESSED_ARGB_1555_VQ_TWID_KOS; + } break; + case 0x01: { + return GL_COMPRESSED_RGB_565_VQ_TWID_KOS; + } break; + case 0x02: { + return GL_COMPRESSED_ARGB_4444_VQ_TWID_KOS; + } + break; + default: + fprintf(stderr, "Invalid texture format"); + return 0; + } + } else { + switch(color) { + case 0: { + return GL_COMPRESSED_ARGB_1555_VQ_KOS; + } break; + case 1: { + return GL_COMPRESSED_RGB_565_VQ_KOS; + } break; + case 2: { + return GL_COMPRESSED_ARGB_4444_VQ_KOS; + } + break; + default: + fprintf(stderr, "Invalid texture format"); + return 0; + } + } + } else { + if(color == 1) { + return GL_UNSIGNED_SHORT_5_6_5; + } + return 0; + } +} + +static GLuint PVR_TextureWidth(unsigned char *HDR) { + return (GLuint)HDR[PVR_HDR_SIZE - 4] | HDR[PVR_HDR_SIZE - 3] << 8; +} + +static GLuint PVR_TextureHeight(unsigned char *HDR) { + return (GLuint)HDR[PVR_HDR_SIZE - 2] | HDR[PVR_HDR_SIZE - 1] << 8; +} diff --git a/examples/dreamcast/cpp/gltest/romdisk/glass.pvr b/examples/dreamcast/gldc/basic/gl/romdisk/glass.pvr old mode 100755 new mode 100644 similarity index 100% copy from examples/dreamcast/cpp/gltest/romdisk/glass.pvr copy to examples/dreamcast/gldc/basic/gl/romdisk/glass.pvr diff --git a/examples/dreamcast/gldc/nehe/Makefile b/examples/dreamcast/gldc/nehe/Makefile index 0f339ab..7722443 100644 --- a/examples/dreamcast/gldc/nehe/Makefile +++ b/examples/dreamcast/gldc/nehe/Makefile @@ -6,7 +6,7 @@ # This will make all the examples, leaving only the elf files. # If you want to clean everything, use 'clean'. -SUBDIRS = nehe02 nehe05 nehe26 +SUBDIRS = nehe02 nehe05 nehe06 nehe08 nehe09 nehe16 nehe26 all: $(patsubst %, _dir_%, $(SUBDIRS)) diff --git a/examples/dreamcast/kgl/nehe/nehe06/Makefile b/examples/dreamcast/gldc/nehe/nehe06/Makefile similarity index 87% copy from examples/dreamcast/kgl/nehe/nehe06/Makefile copy to examples/dreamcast/gldc/nehe/nehe06/Makefile index 9dc0dc5..a4802cc 100644 --- a/examples/dreamcast/kgl/nehe/nehe06/Makefile +++ b/examples/dreamcast/gldc/nehe/nehe06/Makefile @@ -2,7 +2,7 @@ # Nehe06 example adapted from KGL # (c)2013-2014 Josh Pearson # (c)2001 Benoit Miller -# +# TARGET = nehe06.elf OBJS = nehe06.o pvr-texture.o romdisk.o @@ -19,7 +19,7 @@ rm-elf: -rm -f $(TARGET) romdisk.* $(TARGET): $(OBJS) - kos-cc -o $(TARGET) $(OBJS) -L$(KOS_BASE)/lib -lKGL -lm + kos-cc -o $(TARGET) $(OBJS) -L$(KOS_BASE)/lib -lGL -lm run: $(TARGET) $(KOS_LOADER) $(TARGET) diff --git a/examples/dreamcast/kgl/nehe/nehe06/nehe06.c b/examples/dreamcast/gldc/nehe/nehe06/nehe06.c similarity index 97% copy from examples/dreamcast/kgl/nehe/nehe06/nehe06.c copy to examples/dreamcast/gldc/nehe/nehe06/nehe06.c index f1b048e..5f5cf56 100644 --- a/examples/dreamcast/kgl/nehe/nehe06/nehe06.c +++ b/examples/dreamcast/gldc/nehe/nehe06/nehe06.c @@ -9,9 +9,9 @@ #include <kos.h> -#include <KGL/gl.h> -#include <KGL/glu.h> -#include <KGL/glut.h> +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glkos.h> /* Simple KGL example to demonstrate texturing. @@ -144,7 +144,7 @@ int main(int argc, char **argv) { draw_gl(); /* Finish the frame */ - glutSwapBuffers(); + glKosSwapBuffers(); } return 0; diff --git a/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c b/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c new file mode 100644 index 0000000..00592c3 --- /dev/null +++ b/examples/dreamcast/gldc/nehe/nehe06/pvr-texture.c @@ -0,0 +1,176 @@ +/* + KallistiOS 2.0.0 + + pvr-texture.c + (c)2014 Josh PH3NOM Pearson + + Load A PVR Texture to the PVR using Open GL +*/ +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> + +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glkos.h> +#include <GL/glext.h> + +#define PVR_HDR_SIZE 0x20 +#define MAX(x, y) ((x > y) ? x : y) + +static GLuint PVR_TextureHeight(unsigned char *HDR); +static GLuint PVR_TextureWidth(unsigned char *HDR); +static GLuint PVR_TextureFormat(unsigned char *HDR); + +static GLuint _glGetMipmapLevelCount(GLuint width, GLuint height) { + return 1 + floor(log2(MAX(width, height))); +} + +static GLuint _glGetMipmapDataSize(GLuint width, GLuint height) { + GLuint size = 0; + + GLuint i = 0; + + for(; i < _glGetMipmapLevelCount(width, height); ++i) { + size += (width * height * 2); + + if(width > 1) { + width /= 2; + } + + if(height > 1) { + height /= 2; + } + } + + return size; +} + +/* Load a PVR texture file into memory, and then bind the texture to Open GL. + fname is the name of the PVR texture file to be opened and read. + isMipMapped should be passed as 1 if the texture contains MipMap levels, 0 otherwise. + glMipMap should be passed as 1 if Open GL should calculate the Mipmap levels, 0 otherwise */ +GLuint glTextureLoadPVR(char *fname, unsigned char isMipMapped, unsigned char glMipMap) { + FILE *tex = NULL; + uint16_t *TEX0 = NULL; + uint8_t HDR[PVR_HDR_SIZE]; + GLuint texID, texSize, texW, texH, texFormat; + + /* Open the PVR texture file, and get its file size */ + tex = fopen(fname, "rb"); + + if(tex == NULL) { + printf("FILE READ ERROR: %s\n", fname); + + while(1); + } + + fseek(tex, 0, SEEK_END); + texSize = ftell(tex) - PVR_HDR_SIZE; + fseek(tex, 0, SEEK_SET); + + /* Read in the PVR texture file header */ + fread(HDR, 1, PVR_HDR_SIZE, tex); + + /* Extract some information from the PVR texture file header */ + texW = PVR_TextureWidth(HDR); + texH = PVR_TextureHeight(HDR); + texFormat = PVR_TextureFormat(HDR); + + /* Allocate Some Memory for the texture. If we are using Open GL to build the MipMap, + we need to allocate enough space to hold the MipMap texture levels. */ + if(!isMipMapped && glMipMap) + TEX0 = malloc(_glGetMipmapDataSize(texW, texH)); + else + TEX0 = malloc(texSize); + + fread(TEX0, 1, texSize, tex); /* Read in the PVR texture data */ + + /* Generate and bind a texture as normal for Open GL */ + glGenTextures(1, &texID); + glBindTexture(GL_TEXTURE_2D, texID); + + if(texFormat != GL_UNSIGNED_SHORT_5_6_5) + glCompressedTexImage2D(GL_TEXTURE_2D, + 0, + texFormat, + texW, + texH, + 0, + texSize, + TEX0); + else { + //fprintf(stderr, "%x\n", texFormat); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + texW, texH, ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |