/* * Copyright(c) 1997-2001 Id Software, Inc. * Copyright(c) 2002 The Quakeforge Project. * Copyright(c) 2006 Quetoo. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or(at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "video.h" #include "tga.h" /* GL_InitParticleTexture */ void GL_InitParticleTexture(void){ byte data[2][2][4]; int x, y, dx2, dy, d, i; for(x = 0; x < 2; x++){ dx2 = x - 1; dx2 *= dx2; for(y = 0; y < 2; y++){ dy = y - 1; d = 255 -(dx2 +(dy * dy)); if(d <= 0){ d = 0; for(i = 0; i < 3; i++) data[y][x][i] = 0; } else for(i = 0; i < 3; i++) data[y][x][i] = 255; data[y][x][3] =(byte) d; } } r_particletexture = GL_LoadPic("***particle***", (byte *)data, 2, 2, it_sprite, 32); } static byte notexture[8][8] = { {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, }; /* GL_InitParticleTexture */ void GL_InitNoTexture(void){ int x, y; byte data[8][8][4]; for(x = 0; x < 8; x++){ for(y = 0; y < 8; y++){ data[y][x][0] = notexture[x & 3][y & 3] * 255; data[y][x][1] = 0; data[y][x][2] = 0; data[y][x][3] = 255; } } r_notexture = GL_LoadPic("***r_notexture***", (byte *)data, 8, 8, it_wall, 32); } /* GL_Screenshot_f */ void GL_Screenshot_f(void){ byte *buffer, temp; char picname[80]; char checkname[MAX_OSPATH]; int i, c; FILE *f; // create the scrnshots directory if it doesn't exist Com_sprintf(checkname, sizeof(checkname), "%s/scrnshot", FS_Gamedir()); Sys_Mkdir(checkname); // find a file name to save it to strcpy(picname, "quetoo00.tga"); for(i = 0; i <= 99; i++){ picname[6] = i / 10 + '0'; picname[7] = i % 10 + '0'; Com_sprintf(checkname, sizeof(checkname), "%s/scrnshot/%s", FS_Gamedir(), picname); f = fopen(checkname, "rb"); if(!f) break; // file doesn't exist fclose(f); } if(i == 100){ Com_Printf( "GL_Screenshot_f: Couldn't create a file\n"); return; } c = viddef.width * viddef.height * 3; buffer = malloc(c); qglReadPixels(0, 0, viddef.width, viddef.height, GL_RGB, GL_UNSIGNED_BYTE, buffer); // swap rgb to bgr for(i = 0; i < c; i += 3){ temp = buffer[i]; buffer[i] = buffer[i + 2]; buffer[i + 2] = temp; } WriteTGA(checkname, buffer, viddef.width, viddef.height); free(buffer); Com_Printf( "Wrote %s\n", picname); } /* GL_SetDefaultState */ void GL_SetDefaultState(void){ qglClearColor(0, 0, 0 , 0); qglCullFace(GL_FRONT); qglEnable(GL_TEXTURE_2D); qglEnable(GL_ALPHA_TEST); qglAlphaFunc(GL_GREATER, 0.666); qglDisable(GL_DEPTH_TEST); qglDisable(GL_CULL_FACE); qglDisable(GL_BLEND); qglColor4ubv(color_white); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); qglShadeModel(GL_FLAT); GL_TextureMode(gl_texturemode->string); GL_TextureAlphaMode(gl_texturealphamode->string); GL_TextureSolidMode(gl_texturesolidmode->string); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL_TexEnv(GL_REPLACE); }