]> Shamusworld >> Repos - virtualjaguar/commitdiff
New video subsystem supports OpenGL!
authorShamus Hammons <jlhamm@acm.org>
Tue, 2 Sep 2003 18:05:58 +0000 (18:05 +0000)
committerShamus Hammons <jlhamm@acm.org>
Tue, 2 Sep 2003 18:05:58 +0000 (18:05 +0000)
src/include/video.h [new file with mode: 0644]
src/video.cpp [new file with mode: 0644]

diff --git a/src/include/video.h b/src/include/video.h
new file mode 100644 (file)
index 0000000..37877e9
--- /dev/null
@@ -0,0 +1,13 @@
+//
+// VIDEO.H: Header file
+//
+
+#ifndef __VIDEO_H__
+#define __VIDEO_H__
+
+void RenderBackbuffer(void);
+void ResizeScreen(uint32 width, uint32 height);
+uint32 GetSDLScreenPitch(void);
+void ToggleFullscreen(void);
+
+#endif // __VIDEO_H__
diff --git a/src/video.cpp b/src/video.cpp
new file mode 100644 (file)
index 0000000..a035f4a
--- /dev/null
@@ -0,0 +1,108 @@
+//
+// VIDEO.CPP: SDL/local hardware specific video routines
+//
+// by James L. Hammons
+//
+
+#include "types.h"
+#include "tom.h"
+#include "sdlemu_opengl.h"                                                     // For testing only... ;-)
+#include "video.h"
+
+// External global variables
+
+extern SDL_Surface * surface, * mainSurface;
+extern Uint32 mainSurfaceFlags;
+extern int16 * backbuffer;
+extern bool useOpenGL;                                                         // Testing, testing... :-)
+extern bool fullscreen;
+
+//
+// Render the backbuffer to the primary screen surface
+//
+void RenderBackbuffer(void)
+{
+       if (SDL_MUSTLOCK(surface))
+               while (SDL_LockSurface(surface) < 0)
+                       SDL_Delay(10);
+
+       memcpy(surface->pixels, backbuffer, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2);
+
+       if (SDL_MUSTLOCK(surface))
+               SDL_UnlockSurface(surface);
+
+       if (useOpenGL)
+               sdlemu_draw_texture(mainSurface, surface, 1/*1=GL_QUADS*/);
+       else
+       {
+               SDL_Rect rect = { 0, 0, surface->w, surface->h };
+               SDL_BlitSurface(surface, &rect, mainSurface, &rect);
+               SDL_Flip(mainSurface);
+    }
+}
+
+//
+// Resize the main SDL screen & backbuffer
+//
+void ResizeScreen(uint32 width, uint32 height)
+{
+       char window_title[256];
+
+       SDL_FreeSurface(surface);
+       surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
+               16, 0x7C00, 0x03E0, 0x001F, 0);
+       if (surface == NULL)
+       {
+               WriteLog("TOM: Could not create primary SDL surface: %s", SDL_GetError());
+               exit(1);
+       }
+
+       sprintf(window_title, "Virtual Jaguar (%i x %i)", (int)width, (int)height);
+//Hmm.
+/*     mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
+
+       if (mainSurface == NULL)
+       {
+               WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
+               exit(1);
+       }//*/
+
+       SDL_WM_SetCaption(window_title, window_title);
+
+//This seems to work well for resizing...
+       if (useOpenGL)
+               sdlemu_resize_texture(surface, mainSurface);
+}
+
+//
+// Return the screen's pitch
+//
+uint32 GetSDLScreenPitch(void)
+{
+//     extern SDL_Surface * surface;
+
+       return surface->pitch;
+}
+
+//
+// Fullscreen <-> window switching
+//
+//NOTE: This does *NOT* work with OpenGL rendering! !!! FIX !!!
+void ToggleFullscreen(void)
+{
+       fullscreen = !fullscreen;
+       mainSurfaceFlags &= ~SDL_FULLSCREEN;
+
+       if (fullscreen)
+               mainSurfaceFlags |= SDL_FULLSCREEN;
+
+       mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
+
+       if (mainSurface == NULL)
+       {
+               WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
+               exit(1);
+       }
+
+       SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar");
+}