void gr_close() { ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0; if (gl_initialized) { ogl_smash_texture_list_internal(); } if (grd_curscreen) { if (grd_curscreen->sc_canvas.cv_bitmap.bm_data) d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data); d_free(grd_curscreen); } ogl_close_pixel_buffers(); #ifdef _WIN32 if (ogl_rt_loaded) OpenGL_LoadLibrary(false); #endif #ifdef OGLES ogles_destroy(); #ifdef RPI con_printf(CON_DEBUG, "RPi: cleanuing up\n"); if (dispman_display != DISPMANX_NO_HANDLE) { rpi_destroy_element(); con_printf(CON_DEBUG, "RPi: closing display\n"); vc_dispmanx_display_close(dispman_display); dispman_display = DISPMANX_NO_HANDLE; } #endif #endif }
void gr_set_attributes(void) { #ifndef OGLES SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,GameCfg.VSync); if (GameCfg.Multisample) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); } else { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); } #endif ogl_smash_texture_list_internal(); gr_remap_color_fonts(); gr_remap_mono_fonts(); }
void ogl_cmd_texturemode(int argc, char **argv) { if (argc < 2) { cmd_insertf("help %s", argv[0]); return; } if (!stricmp(argv[1], "GL_NEAREST")) { GL_texminfilt = GL_NEAREST; GL_texmagfilt = GL_NEAREST; } else if (!stricmp(argv[1], "GL_LINEAR")) { GL_texminfilt = GL_LINEAR; GL_texmagfilt = GL_LINEAR; } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_NEAREST")) { GL_texminfilt = GL_NEAREST_MIPMAP_NEAREST; GL_texmagfilt = GL_NEAREST; } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_NEAREST")) { GL_texminfilt = GL_LINEAR_MIPMAP_NEAREST; GL_texmagfilt = GL_LINEAR; } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_LINEAR")) { GL_texminfilt = GL_NEAREST_MIPMAP_LINEAR; GL_texmagfilt = GL_NEAREST; } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_LINEAR")) { GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR; GL_texmagfilt = GL_LINEAR; } else return; GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt); ogl_smash_texture_list_internal(); }
int gr_toggle_fullscreen(void) { if (sdl_video_flags & SDL_FULLSCREEN) sdl_video_flags &= ~SDL_FULLSCREEN; else sdl_video_flags |= SDL_FULLSCREEN; if (gl_initialized) { if (sdl_no_modeswitch == 0) { if (!SDL_VideoModeOK(SM_W(Game_screen_mode), SM_H(Game_screen_mode), GameArg.DbgBpp, sdl_video_flags)) { con_printf(CON_URGENT,"Cannot set %ix%i. Fallback to 640x480\n",SM_W(Game_screen_mode), SM_H(Game_screen_mode)); Game_screen_mode=SM(640,480); } if (!SDL_SetVideoMode(SM_W(Game_screen_mode), SM_H(Game_screen_mode), GameArg.DbgBpp, sdl_video_flags)) { Error("Could not set %dx%dx%d opengl video mode: %s\n", SM_W(Game_screen_mode), SM_H(Game_screen_mode), GameArg.DbgBpp, SDL_GetError()); } } #ifdef RPI if (rpi_setup_element(SM_W(Game_screen_mode), SM_H(Game_screen_mode), sdl_video_flags, 1)) { Error("RPi: Could not set up %dx%d element\n", SM_W(Game_screen_mode), SM_H(Game_screen_mode)); } #endif } gr_remap_color_fonts(); gr_remap_mono_fonts(); if (gl_initialized) // update viewing values for menus { glMatrixMode(GL_PROJECTION); glLoadIdentity(); #ifdef OGLES glOrthof(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); #else glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); #endif glMatrixMode(GL_MODELVIEW); glLoadIdentity();//clear matrix glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures } GameCfg.WindowMode = (sdl_video_flags & SDL_FULLSCREEN)?0:1; return (sdl_video_flags & SDL_FULLSCREEN)?1:0; }
int ogl_init_window(int x, int y) { int use_x,use_y,use_bpp; Uint32 use_flags; #ifdef OGLES SDL_SysWMinfo info; Window x11Window = 0; Display* x11Display = 0; EGLint ver_maj, ver_min; EGLint configAttribs[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_DEPTH_SIZE, 16, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_NONE, EGL_NONE }; // explicitely request an OpenGL ES 1.x context EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE, EGL_NONE }; // explicitely request a doublebuffering window EGLint winAttribs[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE, EGL_NONE }; int iConfigs; #endif // OGLES if (gl_initialized) ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures SDL_WM_SetCaption(DESCENT_VERSION, "Descent II"); SDL_WM_SetIcon( SDL_LoadBMP( "d2x-rebirth.bmp" ), NULL ); use_x=x; use_y=y; use_bpp=GameArg.DbgBpp; use_flags=sdl_video_flags; if (sdl_no_modeswitch) { const SDL_VideoInfo *vinfo=SDL_GetVideoInfo(); if (vinfo) { use_x=vinfo->current_w; use_y=vinfo->current_h; use_bpp=vinfo->vfmt->BitsPerPixel; use_flags=SDL_SWSURFACE | SDL_ANYFORMAT; } else { con_printf(CON_URGENT, "Could not query video info\n"); } } if (!SDL_SetVideoMode(use_x, use_y, use_bpp, use_flags)) { #ifdef RPI con_printf(CON_URGENT, "Could not set %dx%dx%d opengl video mode: %s\n (Ignored for RPI)", x, y, GameArg.DbgBpp, SDL_GetError()); #else Error("Could not set %dx%dx%d opengl video mode: %s\n", x, y, GameArg.DbgBpp, SDL_GetError()); #endif } #ifdef OGLES #ifndef RPI // NOTE: on the RPi, the EGL stuff is not connected to the X11 window, // so there is no need to destroy and recreate this ogles_destroy(); #endif SDL_VERSION(&info.version); if (SDL_GetWMInfo(&info) > 0) { if (info.subsystem == SDL_SYSWM_X11) { x11Display = info.info.x11.display; x11Window = info.info.x11.window; con_printf (CON_DEBUG, "Display: %p, Window: %i ===\n", (void*)x11Display, (int)x11Window); } } if (eglDisplay == EGL_NO_DISPLAY) { #ifdef RPI eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); #else eglDisplay = eglGetDisplay((EGLNativeDisplayType)x11Display); #endif if (eglDisplay == EGL_NO_DISPLAY) { con_printf(CON_URGENT, "EGL: Error querying EGL Display\n"); } if (!eglInitialize(eglDisplay, &ver_maj, &ver_min)) { con_printf(CON_URGENT, "EGL: Error initializing EGL\n"); } else { con_printf(CON_DEBUG, "EGL: Initialized, version: major %i minor %i\n", ver_maj, ver_min); } } #ifdef RPI if (rpi_setup_element(x,y,sdl_video_flags,1)) { Error("RPi: Could not set up a %dx%d element\n", x, y); } #endif if (eglSurface == EGL_NO_SURFACE) { if (!eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1)) { con_printf(CON_URGENT, "EGL: Error choosing config\n"); } else { con_printf(CON_DEBUG, "EGL: config chosen\n"); } #ifdef RPI eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)&nativewindow, winAttribs); #else eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (NativeWindowType)x11Window, winAttribs); #endif if ((!TestEGLError("eglCreateWindowSurface")) || eglSurface == EGL_NO_SURFACE) { con_printf(CON_URGENT, "EGL: Error creating window surface\n"); } else { con_printf(CON_DEBUG, "EGL: Created window surface\n"); } } if (eglContext == EGL_NO_CONTEXT) { eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, contextAttribs); if ((!TestEGLError("eglCreateContext")) || eglContext == EGL_NO_CONTEXT) { con_printf(CON_URGENT, "EGL: Error creating context\n"); } else { con_printf(CON_DEBUG, "EGL: Created context\n"); } } eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); if (!TestEGLError("eglMakeCurrent")) { con_printf(CON_URGENT, "EGL: Error making current\n"); } else { con_printf(CON_DEBUG, "EGL: made context current\n"); } #endif linedotscale = ((x/640<y/480?x/640:y/480)<1?1:(x/640<y/480?x/640:y/480)); gl_initialized=1; return 0; }