// // Change to a 2D orthonormal projection // static void SDL2_setOrthoMode(int w, int h) { // enable 2D texture mapping RB_SetState(RB_GLSTATE_TEXTURE0, true); // set viewport glViewport(0, 0, (GLsizei)curscreenwidth, (GLsizei)curscreenheight); // clear model-view matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // set projection matrix to a standard orthonormal projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)w, (GLdouble)h, 0.0, -1.0, 1.0); // disable depth buffer test RB_SetState(RB_GLSTATE_DEPTHTEST, false); }
/* * RB_Clear */ void RB_Clear( int bits, float r, float g, float b, float a ) { // this is required for glClear(GL_DEPTH_BUFFER_BIT) to work if( bits & GL_DEPTH_BUFFER_BIT ) RB_SetState( GLSTATE_DEPTHWRITE ); if( bits & GL_STENCIL_BUFFER_BIT ) qglClearStencil( 128 ); if( bits & GL_COLOR_BUFFER_BIT ) qglClearColor( r, g, b, a ); qglClear( bits ); RB_DepthRange( 0, 1 ); }
/* * RB_Clear */ void RB_Clear( int bits, float r, float g, float b, float a ) { int state = rb.gl.state; if( bits & GL_DEPTH_BUFFER_BIT ) state |= GLSTATE_DEPTHWRITE; if( bits & GL_STENCIL_BUFFER_BIT ) qglClearStencil( 128 ); if( bits & GL_COLOR_BUFFER_BIT ) { state &= ~GLSTATE_NO_COLORWRITE; qglClearColor( r, g, b, a ); } RB_SetState( state ); qglClear( bits ); RB_DepthRange( 0.0f, 1.0f ); }
void RB_DrawSkyDome(int tiles, float rows, int height, int radius, float offset, float topoffs, unsigned int c1, unsigned int c2) { fixed_t x, y, z; fixed_t lx, ly; int i; angle_t an; float tu1, tu2; int r; vtx_t *vtx; int count; lx = ly = count = 0; #define NUM_SKY_DOME_FACES 32 // // front faces are drawn here, so cull the back faces // RB_SetState(GLSTATE_CULL, true); RB_SetCull(GLCULL_BACK); RB_SetState(GLSTATE_DEPTHTEST, true); RB_SetState(GLSTATE_BLEND, true); RB_SetState(GLSTATE_ALPHATEST, false); r = radius / (NUM_SKY_DOME_FACES / 4); // // set pointer for the main vertex list // RB_BindDrawPointers(drawVertex); vtx = drawVertex; // excuse the mess...... #define SKYDOME_VERTEX() vtx->x = FIXED2FLOAT(x); vtx->y = FIXED2FLOAT(y); vtx->z = FIXED2FLOAT(z) #define SKYDOME_UV(u, v) vtx->tu = u; vtx->tv = v #define SKYDOME_LEFT(v, h) \ x = lx; \ y = ly; \ z = (h<<FRACBITS); \ SKYDOME_UV(tu1, v); \ SKYDOME_VERTEX(); \ vtx++ #define SKYDOME_RIGHT(v, h) \ x = lx + FixedMul((r<<FRACBITS), finecosine[angle >> ANGLETOFINESHIFT]); \ y = ly + FixedMul((r<<FRACBITS), finesine[angle >> ANGLETOFINESHIFT]); \ z = (h<<FRACBITS); \ SKYDOME_UV((tu2 * (i + 1)), v); \ SKYDOME_VERTEX(); \ vtx++ tu1 = 0; tu2 = ((float)tiles / (float)NUM_SKY_DOME_FACES) * 0.5f; an = (ANG_MAX / NUM_SKY_DOME_FACES); // // setup vertex data // for(i = 0; i < NUM_SKY_DOME_FACES; ++i) { angle_t angle = an * i; *(unsigned int*)&vtx[0].r = c2; *(unsigned int*)&vtx[1].r = c1; *(unsigned int*)&vtx[2].r = c1; *(unsigned int*)&vtx[3].r = c2; SKYDOME_LEFT(rows, -height); SKYDOME_LEFT(topoffs, height); SKYDOME_RIGHT(topoffs, height); SKYDOME_RIGHT(rows, -height); lx = x; ly = y; RB_AddTriangle(0+count, 1+count, 2+count); RB_AddTriangle(3+count, 0+count, 2+count); count += 4; tu1 += tu2; } for(i = 0; i < NUM_SKY_DOME_FACES * 4; i++) { drawVertex[i].x += -((float)radius / ((float)NUM_SKY_DOME_FACES / 2.0f)); drawVertex[i].y += -((float)radius / (M_PI / 2)); drawVertex[i].z += -offset; } // // draw sky dome // RB_DrawElements(); RB_ResetElements(); RB_SetCull(GLCULL_FRONT); #undef SKYDOME_RIGHT #undef SKYDOME_LEFT #undef SKYDOME_UV #undef SKYDOME_VERTEX #undef NUM_SKY_DOME_FACES }