From 97432189062fb3f977d7c64acd342ae8750fbace Mon Sep 17 00:00:00 2001 From: GPF Date: Fri, 16 Aug 2024 22:10:44 -0700 Subject: [PATCH] fixed some compiler wanrings, fixed viewbmpGL dreamcast demo --- src/video/dreamcast/SDL_dreamcastopengl.c | 14 +++++++--- test/dreamcast/test/viewbmpGL.c | 34 ++++++++--------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/video/dreamcast/SDL_dreamcastopengl.c b/src/video/dreamcast/SDL_dreamcastopengl.c index 25d1108adcfee..cba347c06fddf 100644 --- a/src/video/dreamcast/SDL_dreamcastopengl.c +++ b/src/video/dreamcast/SDL_dreamcastopengl.c @@ -106,7 +106,7 @@ void DREAMCAST_GL_SwapBuffers(_THIS) { } int DREAMCAST_GL_Initialize(_THIS) { - printf("Initializing GLdc...\n"); + printf("Initializing SDL2 GLdc...\n"); glKosInit(); if (DREAMCAST_GL_LoadLibrary(_this, NULL) < 0) { return -1; @@ -119,16 +119,22 @@ void DREAMCAST_GL_Shutdown(_THIS) { glKosShutdown(); } -SDL_GLContext DREAMCAST_GL_CreateContext(_THIS, SDL_Window *window) { - printf("Creating Dreamcast OpenGL context...\n"); - DreamcastGLContext *context = (DreamcastGLContext *) SDL_calloc(1, sizeof(DreamcastGLContext)); +SDL_GLContext DREAMCAST_GL_CreateContext(_THIS, SDL_Window *window) +{ + DreamcastGLContext *context; + + printf("Creating Dreamcast SDL2 OpenGL context...\n"); + + context = (DreamcastGLContext *) SDL_calloc(1, sizeof(DreamcastGLContext)); if (!context) { SDL_OutOfMemory(); return NULL; } + return (SDL_GLContext) context; } + int DREAMCAST_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { DreamcastGLContext *glcontext = (DreamcastGLContext *) context; if (!glcontext) { diff --git a/test/dreamcast/test/viewbmpGL.c b/test/dreamcast/test/viewbmpGL.c index d16071ff747d9..fb99eeafb3e67 100644 --- a/test/dreamcast/test/viewbmpGL.c +++ b/test/dreamcast/test/viewbmpGL.c @@ -17,6 +17,16 @@ GLuint LoadBMPTexture(const char *filename) { printf("Loaded BMP file successfully.\n"); + // Convert BGR to RGB + if (surface->format->BytesPerPixel == 3) { + unsigned char *pixels = (unsigned char *)surface->pixels; + for (int i = 0; i < surface->w * surface->h; ++i) { + unsigned char temp = pixels[i * 3]; + pixels[i * 3] = pixels[i * 3 + 2]; + pixels[i * 3 + 2] = temp; + } + } + glGenTextures(1, &textureID); printf("Generated texture ID: %u\n", textureID); @@ -27,28 +37,8 @@ GLuint LoadBMPTexture(const char *filename) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); printf("Set texture parameters.\n"); - GLenum format; - GLenum internalFormat; - - // Handle pixel format properly for RGB888 - switch (surface->format->BytesPerPixel) { - case 1: // Grayscale - format = GL_LUMINANCE; - internalFormat = GL_LUMINANCE; - break; - case 3: // RGB888 - format = GL_RGB; - internalFormat = GL_RGB; - break; - case 4: // RGBA8888 - format = GL_RGBA; - internalFormat = GL_RGBA; - break; - default: - format = GL_RGB; - internalFormat = GL_RGB; - break; - } + GLenum format = GL_RGB; + GLenum internalFormat = GL_RGB; glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, surface->w, surface->h, 0, format, GL_UNSIGNED_BYTE, surface->pixels); printf("Created texture image. (Width: %d, Height: %d, Format: %d)\n", surface->w, surface->h, internalFormat);