Skip to content

Commit

Permalink
fixed some compiler wanrings, fixed viewbmpGL dreamcast demo
Browse files Browse the repository at this point in the history
  • Loading branch information
GPF committed Aug 17, 2024
1 parent 0a3261b commit 9743218
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
14 changes: 10 additions & 4 deletions src/video/dreamcast/SDL_dreamcastopengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
34 changes: 12 additions & 22 deletions test/dreamcast/test/viewbmpGL.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 9743218

Please sign in to comment.