void InitBloom(int winW,int winH) { bloomTexSize=1024; if((winW>1024)||(winH>1024)) bloomTexSize=2048; if((winW>2048)||(winH>2048)) bloomTexSize=4096; DrawbloomTexSize=bloomTexSize/8; bloomTexId1=EmptyTexture(DrawbloomTexSize); bloomTexId2=EmptyTexture(bloomTexSize); }
BOOL Initialize(void) /* Any GL Init Code & User Initialiazation Goes Here */ { GLfloat global_ambient[4]={0.2f, 0.2f, 0.2f, 1.0f}; /* Set Ambient Lighting To Fairly Dark Light (No Color) */ GLfloat light0pos[4]= {0.0f, 5.0f, 10.0f, 1.0f}; /* Set The Light Position */ GLfloat light0ambient[4]= {0.2f, 0.2f, 0.2f, 1.0f}; /* More Ambient Light */ GLfloat light0diffuse[4]= {0.3f, 0.3f, 0.3f, 1.0f}; /* Set The Diffuse Light A Bit Brighter */ GLfloat light0specular[4]={0.8f, 0.8f, 0.8f, 1.0f}; /* Fairly Bright Specular Lighting */ GLfloat lmodel_ambient[]= {0.2f,0.2f,0.2f,1.0f}; /* And More Ambient Light */ angle = 0.0f; /* Set Starting Angle To Zero */ BlurTexture = EmptyTexture(); /* Create Our Empty Texture */ glLoadIdentity(); /* Reset The Modelview Matrix */ glEnable(GL_DEPTH_TEST); /* Enable Depth Testing */ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient); /* Set The Ambient Light Model */ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); /* Set The Global Ambient Light Model */ glLightfv(GL_LIGHT0, GL_POSITION, light0pos); /* Set The Lights Position */ glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient); /* Set The Ambient Light */ glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse); /* Set The Diffuse Light */ glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular); /* Set Up Specular Lighting */ glEnable(GL_LIGHTING); /* Enable Lighting */ glEnable(GL_LIGHT0); /* Enable Light0 */ glShadeModel(GL_SMOOTH); /* Select Smooth Shading */ glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 0.5); /* Set The Clear Color To Black */ return True; /* Return TRUE (Initialization Successful) */ }
GLvoid NEHE36::InitGL(){ BlurTexture = EmptyTexture(); glEnable(GL_DEPTH_TEST); GLfloat global_ambient[4]={0.2f, 0.2f, 0.2f, 1.0f}; GLfloat light0pos[4]= {0.0f, 5.0f, 10.0f, 1.0f}; GLfloat light0ambient[4]= {0.2f, 0.2f, 0.2f, 1.0f}; GLfloat light0diffuse[4]= {0.3f, 0.3f, 0.3f, 1.0f}; GLfloat light0specular[4]={0.8f, 0.8f, 0.8f, 1.0f}; GLfloat lmodel_ambient[]= {0.2f,0.2f,0.2f,1.0f}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); glLightfv(GL_LIGHT0, GL_POSITION, light0pos); glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glShadeModel(GL_SMOOTH); glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 0.5); }
extern "C" int Initialize (int width, int height) // Any GL Init Code & User Initialiazation Goes Here { wwidth=width; wheight=height; // Start Of User Initialization angle = 0.0f; // Set Starting Angle To Zero BlurTexture = EmptyTexture(); // Create Our Empty Texture glViewport(0 , 0,width ,height); // Set Up A Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix gluPerspective(50, (float)width/(float)height, 5, 2000); // Set Our Perspective glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix return TRUE; // Return TRUE (Initialization Successful) }
BOOL Initialize (GL_Window* window, Keys* keys) // Any GL Init Code & User Initialiazation Goes Here { g_window = window; g_keys = keys; // Start Of User Initialization angle = 0.0f; // Set Starting Angle To Zero BlurTexture = EmptyTexture(); // Create Our Empty Texture glViewport(0 , 0,window->init.width ,window->init.height); // Set Up A Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix gluPerspective(50, (float)window->init.width/(float)window->init.height, 5, 2000); // Set Our Perspective glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix glEnable(GL_DEPTH_TEST); // Enable Depth Testing GLfloat global_ambient[4]={0.2f, 0.2f, 0.2f, 1.0f}; // Set Ambient Lighting To Fairly Dark Light (No Color) GLfloat light0pos[4]= {0.0f, 5.0f, 10.0f, 1.0f}; // Set The Light Position GLfloat light0ambient[4]= {0.2f, 0.2f, 0.2f, 1.0f}; // More Ambient Light GLfloat light0diffuse[4]= {0.3f, 0.3f, 0.3f, 1.0f}; // Set The Diffuse Light A Bit Brighter GLfloat light0specular[4]={0.8f, 0.8f, 0.8f, 1.0f}; // Fairly Bright Specular Lighting GLfloat lmodel_ambient[]= {0.2f,0.2f,0.2f,1.0f}; // And More Ambient Light glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient); // Set The Ambient Light Model glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); // Set The Global Ambient Light Model glLightfv(GL_LIGHT0, GL_POSITION, light0pos); // Set The Lights Position glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient); // Set The Ambient Light glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse); // Set The Diffuse Light glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular); // Set Up Specular Lighting glEnable(GL_LIGHTING); // Enable Lighting glEnable(GL_LIGHT0); // Enable Light0 glShadeModel(GL_SMOOTH); // Select Smooth Shading glMateriali(GL_FRONT, GL_SHININESS, 128); glClearColor(0.0f, 0.0f, 0.0f, 0.5); // Set The Clear Color To Black return TRUE; // Return TRUE (Initialization Successful) }
void ComputeLightMaps (int segNum) { tSegment *segP; tSide *sideP; tLightMap *lmapP; int sideNum, lastSeg, mapNum; short sideVerts [4]; #if 1 # define Xs 8 # define Ys 8 #else int Xs = 8, Ys = 8; #endif int x, y, xy; int v0, v1, v2, v3; GLfloat *pTexColor;// = {0.0, 0.0, 0.0, 1.0}; GLfloat texColor [Xs][Ys][4]; #if 1 # define pixelOffset 0.0 #else double pixelOffset = 0; //0.5 #endif int l, s, nMethod, sideRad; GLfloat tempBright = 0; vmsVector OffsetU, OffsetV, pixelPos [Xs][Ys], *pPixelPos, rayVec, faceNorm, sidePos; double brightPrct, pixelDist; double delta; double f_offset [8] = { 0.0 / (Xs - 1), 1.0 / (Xs - 1), 2.0 / (Xs - 1), 3.0 / (Xs - 1), 4.0 / (Xs - 1), 5.0 / (Xs - 1), 6.0 / (Xs - 1), 7.0 / (Xs - 1) }; #if LMAP_REND2TEX ubyte brightMap [512]; ubyte lightMap [512*3]; tUVL lMapUVL [4]; fix nDist, nMinDist; GLuint lightMapId; int bStart; #endif if (segNum <= 0) { DestroyLightMaps (); if (!InitLightData ()) return; #if LMAP_REND2TEX InitBrightMap (brightMap); memset (&lMapUVL, 0, sizeof (lMapUVL)); #endif } INIT_PROGRESS_LOOP (segNum, lastSeg, gameData.segs.nSegments); //Next Go through each surface and create a lightmap for it. for (mapNum = 6 * segNum, segP = gameData.segs.segments + segNum; segNum < lastSeg; segNum++, segP++) { for (sideNum = 0, sideP = segP->sides; sideNum < 6; sideNum++, mapNum++, sideP++) { #if TEXTURE_CHECK if ((segP->children [sideNum] >= 0) && !IS_WALL (WallNumS (sideP))) continue; //skip open sides #endif GetSideVerts (sideVerts, segNum, sideNum); #if LMAP_REND2TEX OglCreateFBuffer (&lightMaps [mapNum].fbuffer, 64, 64); OglEnableFBuffer (&lightMaps [mapNum].fbuffer); #else lightMaps [mapNum].handle = EmptyTexture (Xs, Ys); OGL_BINDTEX (lightMaps [mapNum].handle); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); nMethod = (sideP->nType == SIDE_IS_QUAD) || (sideP->nType == SIDE_IS_TRI_02); pPixelPos = &pixelPos [0][0]; for (x = 0; x < Xs; x++) { for (y = 0; y < Ys; y++, pPixelPos++) { if (nMethod) { v0 = sideVerts [0]; v2 = sideVerts [2]; if (x >= y) { v1 = sideVerts [1]; //Next calculate this pixel's place in the world (tricky stuff) FindOffset (&OffsetU, gameData.segs.vertices [v0], gameData.segs.vertices [v1], f_offset [x]); //(((double) x) + pixelOffset) / (Xs - 1)); //took me forever to figure out this should be an inverse thingy FindOffset (&OffsetV, gameData.segs.vertices [v1], gameData.segs.vertices [v2], f_offset [y]); //(((double) y) + pixelOffset) / (Ys - 1)); VmVecAdd (pPixelPos, &OffsetU, &OffsetV); VmVecInc (pPixelPos, gameData.segs.vertices + v0); //This should be the real world position of the pixel. //Find Normal VmVecNormal (&faceNorm, gameData.segs.vertices + v0, gameData.segs.vertices + v2, gameData.segs.vertices + v1); } else { //Next calculate this pixel's place in the world (tricky stuff) v3 = sideVerts [3]; FindOffset (&OffsetV, gameData.segs.vertices [v0], gameData.segs.vertices [v3], f_offset [y]); //(((double) y) + pixelOffset) / (Xs - 1)); //Notice y/x and OffsetU/OffsetV are swapped from above FindOffset (&OffsetU, gameData.segs.vertices [v3], gameData.segs.vertices [v2], f_offset [x]); //(((double) x) + pixelOffset) / (Ys - 1)); VmVecAdd (pPixelPos, &OffsetU, &OffsetV); VmVecInc (pPixelPos, gameData.segs.vertices + v0); //This should be the real world position of the pixel. VmVecNormal (&faceNorm, gameData.segs.vertices + v0, gameData.segs.vertices + v3, gameData.segs.vertices + v2); } } else {//SIDE_IS_TRI_02 v1 = sideVerts [1]; v3 = sideVerts [3]; if (Xs - x >= y) { v0 = sideVerts [0]; FindOffset (&OffsetU, gameData.segs.vertices [v0], gameData.segs.vertices [v1], f_offset [x]); //(((double) x) + pixelOffset) / (Xs - 1)); FindOffset (&OffsetV, gameData.segs.vertices [v0], gameData.segs.vertices [v3], f_offset [y]); //(((double) y) + pixelOffset) / (Xs - 1)); VmVecAdd (pPixelPos, &OffsetU, &OffsetV); VmVecInc (pPixelPos, gameData.segs.vertices + v0); //This should be the real world position of the pixel. } else { v2 = sideVerts [2]; //Not certain this is correct, may need to subtract something FindOffset (&OffsetV, gameData.segs.vertices [v2], gameData.segs.vertices [v1], f_offset [Xs - 1 - y]); //((double) ((Xs - 1) - y) + pixelOffset) / (Xs - 1)); FindOffset (&OffsetU, gameData.segs.vertices [v2], gameData.segs.vertices [v3], f_offset [Xs - 1 - x]); //((double) ((Xs - 1) - x) + pixelOffset) / (Xs - 1)); VmVecAdd (pPixelPos, &OffsetU, &OffsetV); VmVecInc (pPixelPos, gameData.segs.vertices + v2); //This should be the real world position of the pixel. } } } } #endif //Calculate LightVal //Next iterate through all the lights and add the light to the pixel every iteration. sideRad = (int) (SideRad (segNum, sideNum) + 0.5); VmVecAvg4 ( &sidePos, &pixelPos [0][0], &pixelPos [Xs-1][0], &pixelPos [Xs-1][Ys-1], &pixelPos [0][Ys-1]); #if 1 pTexColor = texColor [0][0] + 3; memset (texColor, 0, sizeof (texColor)); for (xy = Xs * Ys; xy; xy--, pTexColor += 4) *pTexColor = 1; #else pTexColor = texColor [0][0]; for (x = 0; x < Xs; x++) { for (y = 0; y < Ys; y++, pTexColor += 4) { pTexColor [0] = pTexColor [1] = pTexColor [2] = 0; pTexColor [3] = 1; } } #endif #if LMAP_REND2TEX bStart = 1; #endif for (l = 0, lmapP = lightData; l < numLightMaps; l++, lmapP++) { #if LMAP_REND2TEX nMinDist = 0x7FFFFFFF; // get the distances of all 4 tSide corners to the light source center // scaled by the light source range for (i = 0; i < 4; i++) { int svi = sideVerts [i]; sidePos.x = gameData.segs.vertices [svi].x; sidePos.y = gameData.segs.vertices [svi].y; sidePos.z = gameData.segs.vertices [svi].z; nDist = f2i (VmVecDist (&sidePos, &lmapP->pos)); // calc distance if (nMinDist > nDist) nMinDist = nDist; lMapUVL [i].u = F1_0 * (double) nDist / (double) lmapP->range; // scale distance } if ((lmapP->color [0] + lmapP->color [1] + lmapP->color [2] < 3) && (nMinDist < lmapP->range + sideRad)) { // create and initialize an OpenGL texture for the lightmap InitLightMap (lightMap, brightMap, lmapP->color); glGenTextures (1, &lightMapId); glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 512, 1, GL_RGB, GL_UNSIGNED_BYTE, lightMap); OglActiveTexture (GL_TEXTURE0_ARB); glEnable (GL_TEXTURE_1D); glEnable (GL_BLEND); glBlendFunc (GL_ONE, bStart ? GL_ZERO : GL_ONE); // If processing first light, set the lightmap, else modify it glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, bStart ? GL_REPLACE : GL_ADD); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_RGBA); glBindTexture (GL_TEXTURE_1D, lightMapId); // extend the lightmap to the texture edges glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP); glBegin (GL_QUADS); glColor4f (1.0f, 1.0f, 1.0f, 1.0f); for (i = 0; i < 4; i++) { glMultiTexCoord2f (GL_TEXTURE0_ARB, f2fl (lMapUVL [i].u), f2fl (lMapUVL [i].v)); glVertex3f (f2fl (gameData.segs.vertices [sideVerts [i]].x), f2fl (gameData.segs.vertices [sideVerts [i]].y), f2fl (gameData.segs.vertices [sideVerts [i]].z)); } glEnd (); glDisable (GL_BLEND); glDisable (GL_TEXTURE_1D); glDeleteTextures (1, &lightMapId); bStart = 0; } #else if (f2i (VmVecDist (&sidePos, &lmapP->pos)) < lmapP->range + sideRad) { pPixelPos = &pixelPos [0][0]; pTexColor = texColor [0][0]; #if 1 for (xy = Xs * Ys; xy; xy--, pPixelPos++, pTexColor += 4) { #else for (x = 0; x < Xs; x++) for (y = 0; y < Ys; y++, pPixelPos++, pTexColor += 4) { #endif //Find angle to this light. pixelDist = f2i (VmVecDist (pPixelPos, &lmapP->pos)); if (pixelDist >= lmapP->range) continue; VmVecSub (&rayVec, &lmapP->pos, pPixelPos); delta = f2db (VmVecDeltaAng (&lmapP->dir, &rayVec, NULL)); if (delta < 0) delta = -delta; brightPrct = 1 - (pixelDist / lmapP->range); brightPrct *= brightPrct; //square result if (delta < 0.245) brightPrct /= 4; pTexColor [0] += (GLfloat) (brightPrct * lmapP->color [0]); pTexColor [1] += (GLfloat) (brightPrct * lmapP->color [1]); pTexColor [2] += (GLfloat) (brightPrct * lmapP->color [2]); } } #endif } #if LMAP_REND2TEX lightMaps [mapNum].handle = lightMaps [mapNum].fbuffer.texId; lightMaps [mapNum].fbuffer.texId = 0; OglDestroyFBuffer (&lightMaps [mapNum].fbuffer); #else pPixelPos = &pixelPos [0][0]; pTexColor = texColor [0][0]; for (x = 0; x < Xs; x++) for (y = 0; y < Ys; y++, pPixelPos++, pTexColor += 4) { tempBright = 0; for (s = 0; s < 3; s++) if (pTexColor [s] > tempBright) tempBright = pTexColor [s]; if (tempBright > 1.0) for (s = 0; s < 3; s++) pTexColor [s] /= tempBright; glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, 1, 1, GL_RGBA, GL_FLOAT, pTexColor); } #endif } } } //------------------------------------------------------------------------------ int HaveLightMaps (void) { return (lightData != NULL); } //------------------------------------------------------------------------------ static int segNum = 0; static void CreateLightMapsPoll (int nItems, tMenuItem *m, int *key, int cItem) { GrPaletteStepLoad (NULL); if (segNum < gameData.segs.nSegments) { ComputeLightMaps (segNum); segNum += PROGRESS_INCR; } else { *key = -2; GrPaletteStepLoad (NULL); return; } m [0].value++; m [0].rebuild = 1; *key = 0; GrPaletteStepLoad (NULL); return; }
void FXTVDistort::init(void) { // asignar recursos y tal, cargar ficheros, blabla int demowidth = miDemo->getWidth(); int demoheight = miDemo->getHeight(); int twidth = clp2(demowidth); int theight = clp2(demoheight); this->setTextureSize(twidth, theight); BlurTexture = EmptyTexture(); ccr=0.5; ccg=0.5; ccb=0.5; cca=0.0; fac1=GL_SRC_ALPHA; fac2=GL_ONE_MINUS_SRC_ALPHA; xMax = float(demowidth) / twidth; yMax = float(demoheight) / theight; int i,j; float longint; float floati,floatj; longint=1/TVDISTORTINTERV; for(i=0;i<=TVDISTORTINTERV;i++) { floati=float(i); for(j=0;j<=TVDISTORTINTERV;j++) { floatj=float(j); // la textura va de 0 a 1 texPos[i][j][0]=xMax*(floati)/TVDISTORTINTERV; // x texPos[i][j][1]=yMax*(floatj)/TVDISTORTINTERV; // y texPos[i][j][2]=0.0f; // z // quads de 0.. demowidth blabla quadPos[i][j][0]=-demowidth/2.0+demowidth*(floati)/TVDISTORTINTERV; // x quadPos[i][j][1]=-demoheight/2.0+demoheight*(floatj)/TVDISTORTINTERV; // y quadPos[i][j][2]=0.0f; // z randQuadPos[i][j][0]=2*(float(rand())/RAND_MAX)-1; // de -1..1 randQuadPos[i][j][1]=2*(float(rand())/RAND_MAX)-1; // de -1..1 randQuadPos[i][j][2]=0.0f; } } for(i=0;i<TVD_NUMPARAMS;i++) { params[i]=0.0; } float mu, sigma, x, pi, normal, constante, maximo, xinit, xfin, alturaInterv; mu=9.9465108746; sigma=0.9824992603; pi=3.1415926535; maximo=0; //xinit=7.25; //xfin=13; xinit=4; xfin=16; alturaInterv=float(demoheight)/float(TVDISTORTINTERV); constante=1/(sigma * sqrt(2*pi)); for(i=0;i<=TVDISTORTINTERV;i++) { /* x=4..17 ........ 17-4 = 13*/ x=(float(i)/TVDISTORTINTERV)*(xfin-xinit) + xinit; normal=constante * exp(-(pow((x-mu/sigma),2))/2); normalMagnit[i]=normal/constante; // La division es para normalizar a 1 if(normal>maximo) maximo=normal; normalInterv[i]=(alturaInterv+ normalMagnit[i])*i - demoheight/2; } }