2 // VIDEO.CPP: SDL/local hardware specific video routines
9 #include "sdlemu_opengl.h" // For testing only... ;-)
12 // External global variables
14 extern SDL_Surface * surface, * mainSurface;
15 extern Uint32 mainSurfaceFlags;
16 extern int16 * backbuffer;
17 extern bool useOpenGL; // Testing, testing... :-)
18 extern bool fullscreen;
21 // Render the backbuffer to the primary screen surface
23 void RenderBackbuffer(void)
25 if (SDL_MUSTLOCK(surface))
26 while (SDL_LockSurface(surface) < 0)
29 memcpy(surface->pixels, backbuffer, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2);
31 if (SDL_MUSTLOCK(surface))
32 SDL_UnlockSurface(surface);
35 sdlemu_draw_texture(mainSurface, surface, 1/*1=GL_QUADS*/);
38 SDL_Rect rect = { 0, 0, surface->w, surface->h };
39 SDL_BlitSurface(surface, &rect, mainSurface, &rect);
40 SDL_Flip(mainSurface);
45 // Resize the main SDL screen & backbuffer
47 void ResizeScreen(uint32 width, uint32 height)
49 char window_title[256];
51 SDL_FreeSurface(surface);
52 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
53 16, 0x7C00, 0x03E0, 0x001F, 0);
56 WriteLog("TOM: Could not create primary SDL surface: %s", SDL_GetError());
60 sprintf(window_title, "Virtual Jaguar (%i x %i)", (int)width, (int)height);
62 /* mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
64 if (mainSurface == NULL)
66 WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
70 SDL_WM_SetCaption(window_title, window_title);
72 //This seems to work well for resizing...
74 sdlemu_resize_texture(surface, mainSurface);
78 // Return the screen's pitch
80 uint32 GetSDLScreenPitch(void)
82 // extern SDL_Surface * surface;
84 return surface->pitch;
88 // Fullscreen <-> window switching
90 //NOTE: This does *NOT* work with OpenGL rendering! !!! FIX !!!
91 void ToggleFullscreen(void)
93 fullscreen = !fullscreen;
94 mainSurfaceFlags &= ~SDL_FULLSCREEN;
97 mainSurfaceFlags |= SDL_FULLSCREEN;
99 mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
101 if (mainSurface == NULL)
103 WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
107 SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar");