static void AssertCvarRange( cvar_t *cv, float minVal, float maxVal, qboolean shouldBeIntegral, qboolean shouldBeMult2) { if ( shouldBeIntegral ) { if ( ( int ) cv->value != cv->integer ) { VID_Printf( PRINT_WARNING, "WARNING: cvar '%s' must be integral (%f)\n", cv->name, cv->value ); Cvar_Set( cv->name, va( "%d", cv->integer ) ); } } if ( cv->value < minVal ) { VID_Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f < %f)\n", cv->name, cv->value, minVal ); Cvar_Set( cv->name, va( "%f", minVal ) ); } else if ( cv->value > maxVal ) { VID_Printf( PRINT_WARNING, "WARNING: cvar '%s' out of range (%f > %f)\n", cv->name, cv->value, maxVal ); Cvar_Set( cv->name, va( "%f", maxVal ) ); } if (shouldBeMult2) { if ( (cv->integer&(cv->integer-1)) ) { int newvalue; for (newvalue = 1 ; newvalue < cv->integer ; newvalue<<=1) ; VID_Printf( PRINT_WARNING, "WARNING: cvar '%s' must be multiple of 2(%f)\n", cv->name, cv->value ); Cvar_Set( cv->name, va( "%d", newvalue ) ); } } }
/* ** GL_Strings_f */ void GL_Strings_f( void ) { VID_Printf (PRINT_ALL, "GL_VENDOR: %s\n", gl_config.vendor_string ); VID_Printf (PRINT_ALL, "GL_RENDERER: %s\n", gl_config.renderer_string ); VID_Printf (PRINT_ALL, "GL_VERSION: %s\n", gl_config.version_string ); VID_Printf (PRINT_ALL, "GL_EXTENSIONS: %s\n", gl_config.extensions_string ); }
/* ================= Mod_LoadSpriteModel ================= */ void Mod_LoadSpriteModel (model_t *mod, void *buffer) { dsprite_t *sprin, *sprout; int i; sprin = (dsprite_t *)buffer; sprout = Hunk_Alloc (modfilelen); sprout->ident = LittleLong (sprin->ident); sprout->version = LittleLong (sprin->version); sprout->numframes = LittleLong (sprin->numframes); if (sprout->version != SPRITE_VERSION) VID_Printf (ERR_DROP, "%s has wrong version number (%i should be %i)", mod->name, sprout->version, SPRITE_VERSION); if (sprout->numframes > MAX_MD2SKINS) VID_Printf (ERR_DROP, "%s has too many frames (%i > %i)", mod->name, sprout->numframes, MAX_MD2SKINS); // byte swap everything for (i=0 ; i<sprout->numframes ; i++) { sprout->frames[i].width = LittleLong (sprin->frames[i].width); sprout->frames[i].height = LittleLong (sprin->frames[i].height); sprout->frames[i].origin_x = LittleLong (sprin->frames[i].origin_x); sprout->frames[i].origin_y = LittleLong (sprin->frames[i].origin_y); memcpy (sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME); mod->skins[i] = GL_FindImage (sprout->frames[i].name, it_sprite); } mod->type = mod_sprite; }
void UpdateHardwareGamma(void) { float gamma = (vid_gamma->value); int i; Display* dpy = NULL; SDL_SysWMinfo info; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_VERSION(&info.version); if(!SDL_GetWindowWMInfo(window, &info)) #else if(SDL_GetWMInfo(&info) != 1) #endif { VID_Printf(PRINT_ALL, "Couldn't get Window info from SDL\n"); return; } dpy = info.info.x11.display; XRRScreenResources* res = XRRGetScreenResources(dpy, info.info.x11.window); if(res == NULL) { VID_Printf(PRINT_ALL, "Unable to get xrandr screen resources.\n"); return; } for(i=0; i < res->ncrtc; ++i) { int len = XRRGetCrtcGammaSize(dpy, res->crtcs[i]); size_t rampSize = len*sizeof(Uint16); Uint16* ramp = malloc(rampSize); // TODO: check for NULL if(ramp == NULL) { VID_Printf(PRINT_ALL, "Couldn't allocate &zd byte of memory for gamma ramp - OOM?!\n", rampSize); return; } CalculateGammaRamp(gamma, ramp, len); XRRCrtcGamma* gamma = XRRAllocGamma(len); memcpy(gamma->red, ramp, rampSize); memcpy(gamma->green, ramp, rampSize); memcpy(gamma->blue, ramp, rampSize); free(ramp); XRRSetCrtcGamma(dpy, res->crtcs[i], gamma); XRRFreeGamma(gamma); } XRRFreeScreenResources(res); }
static void RestoreGamma() { int i=0; SDL_SysWMinfo info; Display* dpy = NULL; if(gammaRamps == NULL) return; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_VERSION(&info.version); if(!SDL_GetWindowWMInfo(window, &info)) #else if(SDL_GetWMInfo(&info) != 1) #endif { VID_Printf(PRINT_ALL, "Couldn't get Window info from SDL\n"); return; } dpy = info.info.x11.display; XRRScreenResources* res = XRRGetScreenResources(dpy, info.info.x11.window); if(res == NULL) { VID_Printf(PRINT_ALL, "Unable to get xrandr screen resources.\n"); return; } for(i=0; i < noGammaRamps; ++i) { // in case a display was unplugged or something, noGammaRamps may be > res->ncrtc if(i < res->ncrtc) { int len = XRRGetCrtcGammaSize(dpy, res->crtcs[i]); if(len != gammaRamps[i]->size) { VID_Printf(PRINT_ALL, "WTF, gamma ramp size for display %d has changed from %d to %d!\n", i, gammaRamps[i]->size, len); continue; } XRRSetCrtcGamma(dpy, res->crtcs[i], gammaRamps[i]); } // the ramp needs to be free()d either way XRRFreeGamma(gammaRamps[i]); gammaRamps[i] = NULL; } XRRFreeScreenResources(res); free(gammaRamps); gammaRamps = NULL; VID_Printf(PRINT_ALL, "Restored original Gamma\n"); }
/* ================== R_ScreenShotTGA_f screenshot screenshot [silent] screenshot [levelshot] screenshot [filename] Doesn't print the pacifier message if there is a second arg ================== */ void R_ScreenShotTGA_f (void) { #ifndef _XBOX char checkname[MAX_OSPATH]; int len; static int lastNumber = -1; qboolean silent; if ( !strcmp( Cmd_Argv(1), "levelshot" ) ) { R_LevelShot(); return; } if ( !strcmp( Cmd_Argv(1), "silent" ) ) { silent = qtrue; } else { silent = qfalse; } if ( Cmd_Argc() == 2 && !silent ) { // explicit filename Com_sprintf( checkname, MAX_OSPATH, "screenshots/%s.tga", Cmd_Argv( 1 ) ); } else { // scan for a free filename // if we have saved a previous screenshot, don't scan // again, because recording demo avis can involve // thousands of shots if ( lastNumber == -1 ) { // scan for a free number for ( lastNumber = 0 ; lastNumber <= 9999 ; lastNumber++ ) { R_ScreenshotFilename( lastNumber, checkname, ".tga" ); len = FS_ReadFile( checkname, NULL ); if ( len <= 0 ) { break; // file doesn't exist } } } else { R_ScreenshotFilename( lastNumber, checkname, ".tga" ); } if ( lastNumber == 10000 ) { VID_Printf (PRINT_ALL, "ScreenShot: Couldn't create a file\n"); return; } lastNumber++; } R_TakeScreenshot( 0, 0, glConfig.vidWidth, glConfig.vidHeight, checkname ); if ( !silent ) { VID_Printf (PRINT_ALL, "Wrote %s\n", checkname); } #endif }
/* ** R_ModeList_f */ static void R_ModeList_f( void ) { int i; VID_Printf( PRINT_ALL, "\n" ); for ( i = 0; i < s_numVidModes; i++ ) { VID_Printf( PRINT_ALL, "%s\n", r_vidModes[i].description ); } VID_Printf( PRINT_ALL, "\n" ); }
/* ============== VID_LoadRefresh ============== */ qboolean VID_LoadRefresh(void) { // GetRefAPI_t GetRefAPI; if ( reflib_active ) { R_Shutdown(); VID_FreeReflib (); } VID_Printf(PRINT_INFO, "-------- Loading OpenGL Ref --------\n"); #if 0 if ( ( reflib_library = LoadLibrary( name ) ) == 0 ) { VID_Printf(PRINT_ALL, "LoadLibrary(\"%s\") failed\n", name ); return false; } #endif Swap_Init(); #if 0 if ( ( GetRefAPI = (void *) GetProcAddress( reflib_library, "GetRefAPI" ) ) == 0 ) Com_Error( ERR_FATAL, "GetProcAddress failed on %s", name ); re = GetRefAPI( ri ); #endif #if 0 if (re.api_version != API_VERSION) { VID_FreeReflib (); Com_Error (ERR_FATAL, "%s has incompatible api_version", name); } #endif if ( R_Init( global_hInstance, MainWndProc ) == -1 ) { R_Shutdown(); VID_FreeReflib (); return false; } VID_Printf(PRINT_INFO, "------------------------------------\n"); reflib_active = true; return true; }
/* ================= Mod_LoadPlanes ================= */ void Mod_LoadPlanes (lump_t *l) { int i, j; cplane_t *out; dplane_t *in; int count; int bits; in = (void *)(mod_base + l->fileofs); if (l->filelen % sizeof(*in)) VID_Printf (ERR_DROP, "MOD_LoadBmodel: funny lump size in %s",loadmodel->name); count = l->filelen / sizeof(*in); out = Hunk_Alloc ( count*2*sizeof(*out)); loadmodel->planes = out; loadmodel->numplanes = count; for ( i=0 ; i<count ; i++, in++, out++) { bits = 0; for (j=0 ; j<3 ; j++) { out->normal[j] = LittleFloat (in->normal[j]); if (out->normal[j] < 0) bits |= 1<<j; } out->dist = LittleFloat (in->dist); out->type = LittleLong (in->type); out->signbits = bits; } }
/* ================= Mod_LoadSubmodels ================= */ void Mod_LoadSubmodels (lump_t *l) { dmodel_t *in; mmodel_t *out; int i, j, count; in = (void *)(mod_base + l->fileofs); if (l->filelen % sizeof(*in)) VID_Printf (ERR_DROP, "MOD_LoadBmodel: funny lump size in %s",loadmodel->name); count = l->filelen / sizeof(*in); out = Hunk_Alloc ( count*sizeof(*out)); loadmodel->submodels = out; loadmodel->numsubmodels = count; for ( i=0 ; i<count ; i++, in++, out++) { for (j=0 ; j<3 ; j++) { // spread the mins / maxs by a pixel out->mins[j] = LittleFloat (in->mins[j]) - 1; out->maxs[j] = LittleFloat (in->maxs[j]) + 1; out->origin[j] = LittleFloat (in->origin[j]); } out->radius = RadiusFromBounds (out->mins, out->maxs); out->headnode = LittleLong (in->headnode); out->firstface = LittleLong (in->firstface); out->numfaces = LittleLong (in->numfaces); } }
/* ** GLimp_BeginFrame */ void GLimp_BeginFrame( float camera_separation ) { if ( r_bitdepth->modified ) { if ( r_bitdepth->value != 0 && !glw_state.allowdisplaydepthchange ) { Cvar_SetValue( "r_bitdepth", 0 ); VID_Printf( PRINT_ALL, "r_bitdepth requires Win95 OSR2.x or WinNT 4.x\n" ); } r_bitdepth->modified = false; } if ( camera_separation < 0 && gl_state.stereo_enabled ) { qglDrawBuffer( GL_BACK_LEFT ); } else if ( camera_separation > 0 && gl_state.stereo_enabled ) { qglDrawBuffer( GL_BACK_RIGHT ); } else { qglDrawBuffer( GL_BACK ); } }
/* * Initializes the backend */ void IN_BackendInit(in_state_t *in_state_p) { in_state = in_state_p; m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE); in_mouse = Cvar_Get("in_mouse", "0", CVAR_ARCHIVE); freelook = Cvar_Get("freelook", "1", 0); lookstrafe = Cvar_Get("lookstrafe", "0", 0); sensitivity = Cvar_Get("sensitivity", "3", 0); exponential_speedup = Cvar_Get("exponential_speedup", "0", CVAR_ARCHIVE); m_pitch = Cvar_Get("m_pitch", "0.022", 0); m_yaw = Cvar_Get("m_yaw", "0.022", 0); m_forward = Cvar_Get("m_forward", "1", 0); m_side = Cvar_Get("m_side", "0.8", 0); Cmd_AddCommand("+mlook", IN_MLookDown); Cmd_AddCommand("-mlook", IN_MLookUp); Cmd_AddCommand("force_centerview", IN_ForceCenterView); mouse_x = mouse_y = 0.0; windowed_mouse = Cvar_Get("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE); in_grab = Cvar_Get("in_grab", "2", CVAR_ARCHIVE); vid_fullscreen = Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE); VID_Printf(PRINT_ALL, "Input initialized.\n"); }
void R_LevelShot( void ) { #ifndef _XBOX char checkname[MAX_OSPATH]; byte *buffer; byte *source; byte *src, *dst; int x, y; int r, g, b; float xScale, yScale; int xx, yy; sprintf( checkname, "levelshots/%s.tga", tr.worldDir + strlen("maps/") ); source = (byte*) Z_Malloc( glConfig.vidWidth * glConfig.vidHeight * 3, TAG_TEMP_WORKSPACE, qfalse ); buffer = (byte*) Z_Malloc( LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18, TAG_TEMP_WORKSPACE, qfalse ); memset (buffer, 0, 18); buffer[2] = 2; // uncompressed type buffer[12] = LEVELSHOTSIZE & 255; buffer[13] = LEVELSHOTSIZE >> 8; buffer[14] = LEVELSHOTSIZE & 255; buffer[15] = LEVELSHOTSIZE >> 8; buffer[16] = 24; // pixel size qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_RGB, GL_UNSIGNED_BYTE, source ); // resample from source xScale = glConfig.vidWidth / (4.0*LEVELSHOTSIZE); yScale = glConfig.vidHeight / (3.0*LEVELSHOTSIZE); for ( y = 0 ; y < LEVELSHOTSIZE ; y++ ) { for ( x = 0 ; x < LEVELSHOTSIZE ; x++ ) { r = g = b = 0; for ( yy = 0 ; yy < 3 ; yy++ ) { for ( xx = 0 ; xx < 4 ; xx++ ) { src = source + 3 * ( glConfig.vidWidth * (int)( (y*3+yy)*yScale ) + (int)( (x*4+xx)*xScale ) ); r += src[0]; g += src[1]; b += src[2]; } } dst = buffer + 18 + 3 * ( y * LEVELSHOTSIZE + x ); dst[0] = b / 12; dst[1] = g / 12; dst[2] = r / 12; } } // gamma correct if ( glConfig.deviceSupportsGamma ) { R_GammaCorrect( buffer + 18, LEVELSHOTSIZE * LEVELSHOTSIZE * 3 ); } FS_WriteFile( checkname, buffer, LEVELSHOTSIZE * LEVELSHOTSIZE*3 + 18 ); Z_Free( buffer ); Z_Free( source ); VID_Printf( PRINT_ALL, "Wrote %s\n", checkname ); #endif }
/* * (Un)grab Input */ void GLimp_GrabInput(qboolean grab) { #if SDL_VERSION_ATLEAST(2, 0, 0) if(window != NULL) { SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE); } if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0) { VID_Printf(PRINT_ALL, "WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError()); VID_Printf(PRINT_ALL, " You should probably update to SDL 2.0.3 or newer!\n"); } #else SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF); #endif }
/* =============== LogLight =============== */ static void LogLight( trRefEntity_t *ent ) { int max1, max2; /* if ( !(ent->e.renderfx & RF_FIRST_PERSON ) ) { return; } */ max1 = VectorLength( ent->ambientLight ); /* max1 = ent->ambientLight[0]; if ( ent->ambientLight[1] > max1 ) { max1 = ent->ambientLight[1]; } else if ( ent->ambientLight[2] > max1 ) { max1 = ent->ambientLight[2]; } */ max2 = VectorLength( ent->directedLight ); /* max2 = ent->directedLight[0]; if ( ent->directedLight[1] > max2 ) { max2 = ent->directedLight[1]; } else if ( ent->directedLight[2] > max2 ) { max2 = ent->directedLight[2]; } */ VID_Printf( PRINT_ALL, "amb:%i dir:%i direction: (%4.2f, %4.2f, %4.2f)\n", max1, max2, ent->lightDir[0], ent->lightDir[1], ent->lightDir[2] ); }
/* =============== GL_TextureMode =============== */ void GL_TextureMode( char *string ) { int i; image_t *glt; for (i=0 ; i< NUM_GL_MODES ; i++) { if ( !Q_strcasecmp( modes[i].name, string ) ) break; } if (i == NUM_GL_MODES) { VID_Printf (PRINT_ALL, "bad filter name\n"); return; } gl_filter_min = modes[i].minimize; gl_filter_max = modes[i].maximize; // change all the existing mipmap texture objects for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++) { if (glt->type != it_pic && glt->type != it_sky ) { GL_Bind (glt->texnum); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); } } }
/* ================= Mod_LoadTexinfo ================= */ void Mod_LoadTexinfo (lump_t *l) { texinfo_t *in; mtexinfo_t *out, *step; int i, j, count; char name[MAX_QPATH]; int next; in = (void *)(mod_base + l->fileofs); if (l->filelen % sizeof(*in)) VID_Printf (ERR_DROP, "MOD_LoadBmodel: funny lump size in %s",loadmodel->name); count = l->filelen / sizeof(*in); out = Hunk_Alloc ( count*sizeof(*out)); loadmodel->texinfo = out; loadmodel->numtexinfo = count; for ( i=0 ; i<count ; i++, in++, out++) { for (j=0 ; j<8 ; j++) out->vecs[0][j] = LittleFloat (in->vecs[0][j]); out->flags = LittleLong (in->flags); next = LittleLong (in->nexttexinfo); if (next > 0) out->next = loadmodel->texinfo + next; else out->next = NULL; Com_sprintf (name, sizeof(name), "textures/%s.wal", in->texture); out->image = GL_FindImage (name, it_wall); if (!out->image) { VID_Printf (PRINT_ALL, "Couldn't load %s\n", name); out->image = r_notexture; } } // count animation frames for (i=0 ; i<count ; i++) { out = &loadmodel->texinfo[i]; out->numframes = 1; for (step = out->next ; step && step != out ; step=step->next) out->numframes++; } }
/************************************************************************************************ * R_FogDistance_f * * Console command to change the global fog opacity distance. If you specify nothing on the * * command line, it will display the current fog opacity distance. Specifying a float * * representing the world units away the fog should be completely opaque will change the * * value. * * * * Input * * none * * * * Output / Return * * none * * * ************************************************************************************************/ void R_FogDistance_f(void) { float distance; if (!tr.world) { VID_Printf(PRINT_ALL, "R_FogDistance_f: World is not initialized\n"); return; } if (tr.world->globalFog == -1) { VID_Printf(PRINT_ALL, "R_FogDistance_f: World does not have a global fog\n"); return; } if (Cmd_Argc() <= 1) { // should not ever be 0.0 // if (tr.world->fogs[tr.world->globalFog].tcScale == 0.0) // { // distance = 0.0; // } // else { distance = 1.0 / (8.0 * tr.world->fogs[tr.world->globalFog].tcScale); } VID_Printf(PRINT_ALL, "R_FogDistance_f: Current Distance: %.0f\n", distance); return; } if (Cmd_Argc() != 2) { VID_Printf(PRINT_ALL, "R_FogDistance_f: Invalid number of arguments to set distance\n"); return; } distance = atof(Cmd_Argv(1)); if (distance < 1.0) { distance = 1.0; } tr.world->fogs[tr.world->globalFog].parms.depthForOpaque = distance; tr.world->fogs[tr.world->globalFog].tcScale = 1.0 / ( distance * 8 ); }
/* * Shuts the backend down */ void IN_BackendShutdown(void) { Cmd_RemoveCommand("+mlook"); Cmd_RemoveCommand("-mlook"); Cmd_RemoveCommand("force_centerview"); VID_Printf(PRINT_ALL, "Input shut down.\n"); }
/* ================ Mod_Modellist_f ================ */ void Mod_Modellist_f (void) { int i; model_t *mod; int total; total = 0; VID_Printf (PRINT_ALL,"Loaded models:\n"); for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++) { if (!mod->name[0]) continue; VID_Printf (PRINT_ALL, "%8i : %s\n",mod->extradatasize, mod->name); total += mod->extradatasize; } VID_Printf (PRINT_ALL, "Total resident: %i\n", total); }
/* ** GLW_LoadOpenGL ** ** GLimp_win.c internal function that that attempts to load and use ** a specific OpenGL DLL. */ static qboolean GLW_LoadOpenGL() { char buffer[1024]; qboolean fullscreen; #ifdef HAVE_GLES strcpy( buffer, "libGLES_CM.so" ); #else strcpy( buffer, OPENGL_DRIVER_NAME ); #endif VID_Printf( PRINT_ALL, "...loading %s: ", buffer ); // load the QGL layer if ( QGL_Init( buffer ) ) { #ifdef HAVE_GLES fullscreen = qtrue; #else fullscreen = r_fullscreen->integer; #endif // create the window and set up the context if ( !GLW_StartDriverAndSetMode( buffer, r_mode->integer, fullscreen ) ) { if (r_mode->integer != 3) { if ( !GLW_StartDriverAndSetMode( buffer, 3, fullscreen ) ) { goto fail; } } else goto fail; } return qtrue; } else { VID_Printf( PRINT_ALL, "failed\n" ); } fail: QGL_Shutdown(); return qfalse; }
/* ===================== R_PerformanceCounters ===================== */ void R_PerformanceCounters( void ) { #ifndef _XBOX if ( !r_speeds->integer ) { // clear the counters even if we aren't printing memset( &tr.pc, 0, sizeof( tr.pc ) ); memset( &backEnd.pc, 0, sizeof( backEnd.pc ) ); return; } if (r_speeds->integer == 1) { const float texSize = R_SumOfUsedImages( qfalse )/(8*1048576.0f)*(r_texturebits->integer?r_texturebits->integer:glConfig.colorBits); VID_Printf (PRINT_ALL, "%i/%i shdrs/srfs %i leafs %i vrts %i/%i tris %.2fMB tex %.2f dc\n", backEnd.pc.c_shaders, backEnd.pc.c_surfaces, tr.pc.c_leafs, backEnd.pc.c_vertexes, backEnd.pc.c_indexes/3, backEnd.pc.c_totalIndexes/3, texSize, backEnd.pc.c_overDraw / (float)(glConfig.vidWidth * glConfig.vidHeight) ); } else if (r_speeds->integer == 2) { VID_Printf (PRINT_ALL, "(patch) %i sin %i sclip %i sout %i bin %i bclip %i bout\n", tr.pc.c_sphere_cull_patch_in, tr.pc.c_sphere_cull_patch_clip, tr.pc.c_sphere_cull_patch_out, tr.pc.c_box_cull_patch_in, tr.pc.c_box_cull_patch_clip, tr.pc.c_box_cull_patch_out ); VID_Printf (PRINT_ALL, "(md3) %i sin %i sclip %i sout %i bin %i bclip %i bout\n", tr.pc.c_sphere_cull_md3_in, tr.pc.c_sphere_cull_md3_clip, tr.pc.c_sphere_cull_md3_out, tr.pc.c_box_cull_md3_in, tr.pc.c_box_cull_md3_clip, tr.pc.c_box_cull_md3_out ); } else if (r_speeds->integer == 3) { VID_Printf (PRINT_ALL, "viewcluster: %i\n", tr.viewCluster ); } else if (r_speeds->integer == 4) { if ( backEnd.pc.c_dlightVertexes ) { VID_Printf (PRINT_ALL, "dlight srf:%i culled:%i verts:%i tris:%i\n", tr.pc.c_dlightSurfaces, tr.pc.c_dlightSurfacesCulled, backEnd.pc.c_dlightVertexes, backEnd.pc.c_dlightIndexes / 3 ); } } else if (r_speeds->integer == 5 ) { VID_Printf( PRINT_ALL, "zFar: %.0f\n", tr.viewParms.zFar ); } else if (r_speeds->integer == 6 ) { VID_Printf( PRINT_ALL, "flare adds:%i tests:%i renders:%i\n", backEnd.pc.c_flareAdds, backEnd.pc.c_flareTests, backEnd.pc.c_flareRenders ); } else if (r_speeds->integer == 7) { const float texSize = R_SumOfUsedImages(qtrue) / (1048576.0f); const float backBuff= glConfig.vidWidth * glConfig.vidHeight * glConfig.colorBits / (8.0f * 1024*1024); const float depthBuff= glConfig.vidWidth * glConfig.vidHeight * glConfig.depthBits / (8.0f * 1024*1024); const float stencilBuff= glConfig.vidWidth * glConfig.vidHeight * glConfig.stencilBits / (8.0f * 1024*1024); VID_Printf (PRINT_ALL, "Tex MB %.2f + buffers %.2f MB = Total %.2fMB\n", texSize, backBuff*2+depthBuff+stencilBuff, texSize+backBuff*2+depthBuff+stencilBuff); } #endif memset( &tr.pc, 0, sizeof( tr.pc ) ); memset( &backEnd.pc, 0, sizeof( backEnd.pc ) ); }
/* * origname: the filename to be opened, might be without extension * type: extension of the type we wanna open ("jpg", "png" or "tga") * pic: pointer RGBA pixel data will be assigned to */ qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height) { char filename[256]; Q_strlcpy(filename, origname, sizeof(filename)); /* Add the extension */ if (strcmp(COM_FileExtension(filename), type) != 0) { Q_strlcat(filename, ".", sizeof(filename)); Q_strlcat(filename, type, sizeof(filename)); } *pic = NULL; byte* rawdata = NULL; int rawsize = FS_LoadFile(filename, (void **)&rawdata); if (rawdata == NULL) { return false; } int w, h, bytesPerPixel; byte* data = NULL; data = stbi_load_from_memory(rawdata, rawsize, &w, &h, &bytesPerPixel, STBI_rgb_alpha); if (data == NULL) { VID_Printf(PRINT_ALL, "stb_image couldn't load data from %s: %s!\n", filename, stbi_failure_reason()); FS_FreeFile(rawdata); return false; } FS_FreeFile(rawdata); VID_Printf(PRINT_DEVELOPER, "LoadSTB() loaded: %s\n", filename); *pic = data; *width = w; *height = h; return true; }
METHODDEF void output_message (j_common_ptr cinfo) { char buffer[JMSG_LENGTH_MAX]; /* Create the message */ (*cinfo->err->format_message) (cinfo, buffer); /* Send it to stderr, adding a newline */ VID_Printf(PRINT_ALL, "%s\n", buffer); }
/* * Initialzes the SDL OpenGL context */ int GLimp_Init(void) { if (!SDL_WasInit(SDL_INIT_VIDEO)) { char driverName[64]; if (SDL_Init(SDL_INIT_VIDEO) == -1) { VID_Printf(PRINT_ALL, "Couldn't init SDL video: %s.\n", SDL_GetError()); return false; } SDL_VideoDriverName(driverName, sizeof(driverName) - 1); VID_Printf(PRINT_ALL, "SDL video driver is \"%s\".\n", driverName); } return true; }
void UpdateHardwareGamma(void) { float gamma = (vid_gamma->value); Uint16 ramp[256]; CalculateGammaRamp(gamma, ramp, 256); #if SDL_VERSION_ATLEAST(2, 0, 0) if(SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0) { #else if(SDL_SetGammaRamp(ramp, ramp, ramp) < 0) { #endif VID_Printf(PRINT_ALL, "Setting gamma failed: %s\n", SDL_GetError()); } } #endif // X11GAMMA static qboolean IsFullscreen() { #if SDL_VERSION_ATLEAST(2, 0, 0) return !!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN); #else return !!(window->flags & SDL_FULLSCREEN); #endif } static qboolean CreateSDLWindow(int flags) { #if SDL_VERSION_ATLEAST(2, 0, 0) int windowPos = SDL_WINDOWPOS_UNDEFINED; // TODO: support fullscreen on different displays with SDL_WINDOWPOS_UNDEFINED_DISPLAY(displaynum) window = SDL_CreateWindow("Yamagi Quake II", windowPos, windowPos, vid.width, vid.height, flags); if(window == NULL) { return false; } context = SDL_GL_CreateContext(window); if(context == NULL) { SDL_DestroyWindow(window); window = NULL; return false; } return true; #else window = SDL_SetVideoMode(vid.width, vid.height, 0, flags); SDL_EnableUNICODE(SDL_TRUE); return window != NULL; #endif }
/* ================= Mod_LoadSurfedges ================= */ void Mod_LoadSurfedges (lump_t *l) { int i, count; int *in, *out; in = (void *)(mod_base + l->fileofs); if (l->filelen % sizeof(*in)) VID_Printf (ERR_DROP, "MOD_LoadBmodel: funny lump size in %s",loadmodel->name); count = l->filelen / sizeof(*in); if (count < 1 || count >= MAX_MAP_SURFEDGES) VID_Printf (ERR_DROP, "MOD_LoadBmodel: bad surfedges count in %s: %i", loadmodel->name, count); out = Hunk_Alloc ( count*sizeof(*out)); loadmodel->surfedges = out; loadmodel->numsurfedges = count; for ( i=0 ; i<count ; i++) out[i] = LittleLong (in[i]); }
/* ** GLW_StartDriverAndSetMode */ static qboolean GLW_StartDriverAndSetMode( const char *drivername, int mode, qboolean fullscreen ) { rserr_t err; err = (rserr_t) GLW_SetMode( drivername, mode, fullscreen ); switch ( err ) { case RSERR_INVALID_FULLSCREEN: VID_Printf( PRINT_ALL, "...WARNING: fullscreen unavailable in this mode\n" ); return qfalse; case RSERR_INVALID_MODE: VID_Printf( PRINT_ALL, "...WARNING: could not set the given mode (%d)\n", mode ); return qfalse; default: break; } return qtrue; }
/* * Changes the video mode */ int GLimp_SetMode(int *pwidth, int *pheight, int mode, qboolean fullscreen) { VID_Printf(PRINT_ALL, "setting mode %d:", mode); /* mode -1 is not in the vid mode table - so we keep the values in pwidth and pheight and don't even try to look up the mode info */ if ((mode != -1) && !VID_GetModeInfo(pwidth, pheight, mode)) { VID_Printf(PRINT_ALL, " invalid mode\n"); return rserr_invalid_mode; } VID_Printf(PRINT_ALL, " %d %d\n", *pwidth, *pheight); if (!GLimp_InitGraphics(fullscreen)) { return rserr_invalid_mode; } return rserr_ok; }
/* ================== GL_ScreenShot_f ================== */ void GL_ScreenShot_f (void) { byte *buffer; #ifdef WIN32 DWORD tID; #endif buffer = (byte *) malloc(viddef.width*viddef.height*3); glReadPixels (0, 0, viddef.width, viddef.height, GL_RGB, GL_UNSIGNED_BYTE, buffer ); #if defined(_WIN32) && defined(USE_PNG) if (!strcmp (Cmd_Argv(1), "jpg")) { //GL_ScreenShot_JPG (buffer); } else { #ifdef USE_THREADS //_beginthreadex (NULL, 0, (unsigned int (__stdcall *)(void *))png_write_thread, (void *)buffer, 0, &tID); CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)png_write_thread, (LPVOID)buffer, 0, &tID); VID_Printf (PRINT_ALL, "Taking PNG screenshot...\n"); #else // USE_THREADS png_write_thread (buffer); #endif // USE_THREADS } #else // WIN32 #ifdef USE_JPEG GL_ScreenShot_JPG (buffer); #else // USE_JPEG VID_Printf (PRINT_ALL, "No JPEG support, no screenshot...\n"); #endif // USE_JPEG #endif // WIN32 }