void Map2D::DrawTranslucent( const glImage *Tiles ) { TxOff = (TxOff + 1) & 31; glPushMatrix(); glPolyFmt( POLY_ALPHA(15) | POLY_CULL_FRONT | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) ); for( int y = 0; y < Height; y++ ) { for( int x = 0; x < Width ; x++ ) { int Tile = GetElement(x,y); switch( Tile ) { case WATER: DrawFrontCube( (x * TILE_SIZE_3D) + floattof32(0.5), (y * TILE_SIZE_3D) + floattof32(0.5), 0, 0, -TxOff, &Tiles[0] ); break; case TOP_WATER: DrawFrontTopCube( (x * TILE_SIZE_3D) + floattof32(0.5), (y * TILE_SIZE_3D) + floattof32(0.5), 0, 0, -TxOff, &Tiles[0] ); break; } } } glPolyFmt( POLY_ALPHA(31) | POLY_CULL_NONE | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) ); glPopMatrix(1); }
void Scene::renderString(const char* str, f32 x, f32 y, int r, int g, int b) { int l = 0; while(str[l] != 0) l++; x -= (l*25) / 2; int i = 0; while(str[i] != 0) { glPolyFmt(POLY_ALPHA(27+rand()%3) | POLY_ID(BG_FX2_POLYID) | POLY_CULL_NONE); int rr = r+irand(80); if(rr < 0) rr = 0; if(rr > 255) rr = 255; int gg = g+irand(80); if(gg < 0) gg = 0; if(gg > 255) gg = 255; int bb = b+irand(80); if(bb < 0) bb = 0; if(bb > 255) bb = 255; glColor3b(rr, gg, bb); renderChar(str[i], x+frand(1), y+frand(2), 10); x += 25; i++; } }
void App_Test::display_Model() { // gluLookAtf32( this->camera.getPosition()->get_vec_ox(),this->camera.getPosition()->get_vec_oy(),this->camera.getPosition()->get_vec_oz(), // this->camera.getLookAt()->get_vec_ox(),this->camera.getLookAt()->get_vec_oy(),this->camera.getLookAt()->get_vec_oz(), // 0,4096,0 // ); // glLoadIdentity(); glEnable(GL_TEXTURE_2D); glEnable(GL_ANTIALIAS); glEnable(GL_OUTLINE); glLight(0, RGB15(31,31,31) , 0, floattov10(-6.0), floattov10(-1.0)); glSetOutlineColor(0,RGB15(0,0,0)); glPolyFmt(POLY_ID(0) | POLY_ALPHA(31)|POLY_CULL_NONE | POLY_FORMAT_LIGHT0 | POLY_TOON_HIGHLIGHT); // glPolyFmt(POLY_ALPHA(31)|POLY_CULL_NONE | POLY_FORMAT_LIGHT0); glColor3b(31,31,31); glBindTexture(GL_TEXTURE_2D, this->textureID[0]); glTranslatef(0,-6,0); glRotatef(90,-1,0,0); glRotatef(-90,0,0,1); glCallList( (u32 *) this->model_selected); glEnd(); }
void CharActor::renderUnrotated() { glPolyFmt(POLY_ALPHA(27+rand()%3) | POLY_ID(BG_FX2_POLYID) | POLY_CULL_NONE); glColor3b(255, 160+irand(80), 0); renderChar(c, x+frand(1), y+frand(2), size); }
void drawTurretStuff(turret_struct* t) { if(!t || !t->used || t->dead)return; drawLaser(t->laserOrigin,t->laserDestination); if(t->laserThroughPortal)drawLaser(t->laserOrigin2,t->laserDestination2); //TEMP TEST BILLBOARD vect3D u1=vect(t->OBB->transformationMatrix[0],t->OBB->transformationMatrix[3],t->OBB->transformationMatrix[6]); vect3D u2=vect(t->OBB->transformationMatrix[1],t->OBB->transformationMatrix[4],t->OBB->transformationMatrix[7]); vect3D u3=vect(t->OBB->transformationMatrix[2],t->OBB->transformationMatrix[5],t->OBB->transformationMatrix[8]); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_ID(63)); GFX_COLOR=RGB15(31,31,31); applyMTL(turretShotTexture); if(t->drawShot[0]) { glPushMatrix(); glTranslatef32(t->laserOrigin.x, t->laserOrigin.y, t->laserOrigin.z); glTranslatef32(u3.x/128, u3.y/128, u3.z/128); glTranslatef32(u1.x/32, u1.y/32, u1.z/32); glScalef32(inttof32(1)/16,inttof32(1)/16,inttof32(1)/16); glRotatef32i(t->shotAngle[0],u3.x,u3.y,u3.z); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(-u1.x/2-u2.x, -u1.y/2-u2.y, -u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(0)); glVertex3v16(+u1.x/2-u2.x, +u1.y/2-u2.y, +u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(64)); glVertex3v16(+u1.x/2+u2.x, +u1.y/2+u2.y, +u1.z/2+u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(-u1.x/2+u2.x, -u1.y/2+u2.y, -u1.z/2+u2.z); glPopMatrix(1); } if(t->drawShot[1]) { glPushMatrix(); glTranslatef32(t->laserOrigin.x, t->laserOrigin.y, t->laserOrigin.z); glTranslatef32(u3.x/128, u3.y/128, u3.z/128); glTranslatef32(-u1.x/32, -u1.y/32, -u1.z/32); glScalef32(inttof32(1)/16,inttof32(1)/16,inttof32(1)/16); glRotatef32i(t->shotAngle[1],u3.x,u3.y,u3.z); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(-u1.x/2-u2.x, -u1.y/2-u2.y, -u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(0)); glVertex3v16(+u1.x/2-u2.x, +u1.y/2-u2.y, +u1.z/2-u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(32), inttot16(64)); glVertex3v16(+u1.x/2+u2.x, +u1.y/2+u2.y, +u1.z/2+u2.z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(-u1.x/2+u2.x, -u1.y/2+u2.y, -u1.z/2+u2.z); glPopMatrix(1); } }
void drawDoor(door_struct* d) { if(!d || !d->used)return; glPushMatrix(); u32 params=POLY_ALPHA(31)|POLY_CULL_FRONT|POLY_ID(30+d->id)|POLY_TOON_HIGHLIGHT|POLY_FOG; setupObjectLighting(NULL, d->position, ¶ms); glTranslate3f32(d->position.x,d->position.y,d->position.z); if(d->orientation)glRotateYi(8192); renderModelFrameInterp(d->modelInstance.currentFrame,d->modelInstance.nextFrame,d->modelInstance.interpCounter,d->modelInstance.model,params,false,d->modelInstance.palette,RGB15(31,31,31)); glPopMatrix(1); }
void drawLaser(vect3D orig, vect3D target) { unbindMtl(); glPolyFmt(POLY_ID(63)); GFX_COLOR=RGB15(31,0,0); glPushMatrix(); vect3D v=vectDifference(target,orig); glBegin(GL_TRIANGLES); glTranslatef32(orig.x, orig.y, orig.z); glVertex3v16(0, 0, 0); glTranslatef32(v.x, v.y, v.z); glVertex3v16(0, 0, 0); glVertex3v16(0, 0, 0); glPopMatrix(1); }
void SeaActor::renderPerspective() { glPolyFmt(POLY_ALPHA(20) | POLY_ID(BG_FX1_POLYID) | POLY_CULL_NONE); glColor3b(10, 50, 255); setTexture(13); ydelta = 0; renderSea(-6, 6, -10, -5, 1, false); renderSea(-10, 10, -5, -2, 1, true); renderSea(-18, 18, -2, 5, 2, true); renderSea(-20, 22, 6, 12, 4, true); }
static void Splash_Drawer(void) { I_CheckGFX(); GFX_ORTHO(); if(screenalpha > 1) { GFX_POLY_FORMAT = POLY_ALPHA(screenalpha) | POLY_ID(63) | POLY_CULL_NONE | POLY_MODULATION; GFX_TEX_FORMAT = 0; GFX_PAL_FORMAT = 0; GFX_COLOR = 0; GFX_SCREENRECT(); } if(screenalpha < 0x1F) { switch(splashstage) { case 0: R_SlamBackground("IDLOGO", 70, 28, 0xFFFFF); break; case 1: R_SlamBackground("WMSCRED1", 0, 58, 0xFFFFF); break; case 2: R_SlamBackground("USLEGAL", 0, 50, 0xFFFFF); break; default: break; } } }
void Map2D::DrawDebug( const glImage *Tiles ) { glPushMatrix(); glPolyFmt( POLY_ALPHA(31) | POLY_CULL_FRONT | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) ); for( int y = 0; y < Height; y++ ) { for( int x = 0; x < Width ; x++ ) { int Tile = GetElement(x,y); switch( Tile ) { case BRICK: // offset by 0.5 so that (0,0) is top left of tile like standard 2D //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[4] ); break; case TOP_BRICK: //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[0] ); break; case TOP_BRICK_MOSS_TOP: //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[0] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[7] ); break; case BRICK_MOSS_BOTTOM: //DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[4] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[6] ); break; case SPIKE: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 0, GL_FLIP_NONE, &Tiles[2] ); //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] ); break; case INVISIBLE: glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 8+ TILE_SIZE_3D, GL_FLIP_NONE, &Tiles[2] ); break; case LADDER: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[1] ); break; case TOP_LADDER: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[1] ); break; case TOP_LADDER_HANDLE: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[5] ); break; case SIGN: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[3] ); break; case MOSS_BOTTOM: //glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[6] ); break; case BLOCK_COLLIDE: glSprite3D( x * TILE_SIZE_3D, y * TILE_SIZE_3D, -TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] ); break; } } } glPopMatrix(1); }
int main() { // initialize gl glInit(); u32 rotateX = 0; u32 rotateY = 0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // used to hold touched position touchPosition touchXY; lcdMainOnBottom(); // we are going to be touching the 3D display // enable edge outlining, this will be used to show which object is selected glEnable(GL_OUTLINE); //set the first outline color to white glSetOutlineColor(0,RGB15(31,31,31)); int viewport[]={0,0,255,191}; // used later for gluPickMatrix() // setup the rear plane glClearColor(0,0,0,0); // set BG to black and clear glClearPolyID(0); // the BG and polygons will have the same ID unless a polygon is highlighted glClearDepth(0x7FFF); // setup the camera gluLookAt( 0.0, 0.0, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0); // setup the light while(1) { // handle key input scanKeys(); u16 keys = keysHeld(); if(!(keys & KEY_UP)) rotateX += 3; if(!(keys & KEY_DOWN)) rotateX -= 3; if(!(keys & KEY_LEFT)) rotateY += 3; if(!(keys & KEY_RIGHT)) rotateY -= 3; // get touchscreen position touchRead(&touchXY); glViewport(0,0,255,191); // set the viewport to fullscreen // setup the projection matrix for regular drawing glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, 256.0 / 192.0, 0.1, 20); glMatrixMode(GL_MODELVIEW); // use the modelview matrix while drawing glPushMatrix(); // save the state of the current matrix(the modelview matrix) { glTranslatef32(0,0,floattof32(-6)); glRotateXi(rotateX); // add X rotation to the modelview matrix glRotateYi(rotateY); // add Y rotation to the modelview matrix glPushMatrix(); // save the state of the modelview matrix while making the first pass { // draw the scene for displaying glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location if(clicked==CONE) { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining } else { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG) } glCallList((u32*)cone_bin); // draw a green cone from a predefined packed command list glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location if(clicked==CYLINDER) { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining } else { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG) } glCallList((u32*)cylinder_bin); // draw a blue cylinder from a predefined packed command list glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location if(clicked==SPHERE) { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining } else { glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG) } glCallList((u32*)sphere_bin); // draw a red sphere from a predefined packed command list } glPopMatrix(1); // restores the modelview matrix to where it was just rotated // draw the scene again for picking { clicked = NOTHING; //reset what was clicked on closeW = 0x7FFFFFFF; //reset the distance //set the viewport to just off-screen, this hides all rendering that will be done during picking glViewport(0,192,0,192); // setup the projection matrix for picking glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPickMatrix((touchXY.px),(191-touchXY.py),4,4,viewport); // render only what is below the cursor gluPerspective(60, 256.0 / 192.0, 0.1, 20); // this must be the same as the original perspective matrix glMatrixMode(GL_MODELVIEW); // switch back to modifying the modelview matrix for drawing glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location startCheck(); glCallList((u32*)cone_bin); // draw a cone from a predefined packed command list endCheck(CONE); glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location startCheck(); glCallList((u32*)cylinder_bin); // draw a cylinder from a predefined packed command list endCheck(CYLINDER); glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location startCheck(); glCallList((u32*)sphere_bin); // draw a sphere from a predefined packed command list endCheck(SPHERE); } } glPopMatrix(1); // restores the modelview matrix to its original state glFlush(0); // wait for everything to be drawn before starting on the next frame } return 0; }//end main
void renderObject(LevelObj& obj, f32 xx, f32 yy, Scene* sc) { int x = xx.toint(); int y = yy.toint(); const int z = 1000; if(obj.type == BEH_WATER || obj.type == BEH_LAVA || obj.type == BEH_WATERDOWN || obj.type == BEH_LAVADOWN) { bool top = obj.type == BEH_WATER || obj.type == BEH_LAVA; bool lava = obj.type == BEH_LAVADOWN || obj.type == BEH_LAVA; if(top) { setTexture(TEX_VERTGRAD); glPolyFmt(POLY_ALPHA(28) | POLY_ID(WATER_POLYID) | POLY_CULL_NONE); glBegin(GL_QUAD_STRIP); int divnum = 32; f32 dx = obj.x[1]-obj.x[0]; f32 dy = obj.y[1]-obj.y[0]; f32 len = fsqrt(dx*dx+dy*dy); if(len < 90) divnum = 16; if(len < 45) divnum = 8; if(!top) divnum = 1; for(int j = 0; j <= divnum; j++) { int x1 = (obj.x[0]*j+obj.x[1]*(divnum-j))/divnum; int y1 = (obj.y[0]*j+obj.y[1]*(divnum-j))/divnum; int x2 = (obj.x[3]*j+obj.x[2]*(divnum-j))/divnum; int y2 = (obj.y[3]*j+obj.y[2]*(divnum-j))/divnum; f32 dx = x2-x1; f32 dy = y2-y1; f32 len = fsqrt(dx*dx+dy*dy); dx /= len; dy /= len; int in = x1*19+y1*14+sc->time*20; int in2 = x1*24-y1*18-sc->time*12; // int in2 = x1*18-y1*21-sc->time*15; if(top) { int xw = 0; if(!lava) { xw += sinLerp(in*40)/600; xw += sinLerp(in2*23)/600; } else { xw += sinLerp(in*27)/800; xw += sinLerp(in2*13)/300; } dx *= xw; dy *= xw; x1 += dx.toint(); y1 += dy.toint(); if(!lava) glColor3b(130, 180, 255); else glColor3b(255, 180, 30); } GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(64)); glVertex3v16((x1-x)*32, (y1-y)*32, z); if(!lava) glColor3b(20, 50, 215); else glColor3b(255, 60, 0); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(0)); glVertex3v16((x2-x)*32, (y2-y)*32, z); } glEnd(); } else { if(!lava) glColor3b(20, 50, 215); else glColor3b(255, 60, 0); setNoTexture(); glPolyFmt(POLY_ALPHA(7) | POLY_ID(WATER_POLYID) | POLY_CULL_NONE); glBegin(GL_QUAD); glVertex3v16((obj.x[0]-x)*32, (obj.y[0]-y)*32, z); glVertex3v16((obj.x[1]-x)*32, (obj.y[1]-y)*32, z); glVertex3v16((obj.x[2]-x)*32, (obj.y[2]-y)*32, z); glVertex3v16((obj.x[3]-x)*32, (obj.y[3]-y)*32, z); glEnd(); } } else { int a = 28; if(obj.type == BEH_WALL) glColor3b(200, 200, 255); else if(obj.type == BEH_BOUNCY) glColor3b(255, 100, 210); else if(obj.type == BEH_PORTAL1) glColor3b(100, 255, 20); else if(obj.type == BEH_PORTAL2) glColor3b(30, 140, 210); if(obj.type == BEH_PORTAL1 && sc->switchesActive[0]) a = 6; if(obj.type == BEH_PORTAL2 && sc->switchesActive[1]) a = 6; if(debugShown) { if(obj.state == 1) glColor3b(0, 200, 0); else if(obj.state == 2) glColor3b(0, 000, 200); } setTexture(TEX_INVBALL); glPolyFmt(POLY_ALPHA(a) | POLY_ID(LEVEL_POLYID) | POLY_CULL_NONE); glBegin(GL_QUAD); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(0)); glVertex3v16((obj.x[0]-x)*32, (obj.y[0]-y)*32, z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(64)); glVertex3v16((obj.x[1]-x)*32, (obj.y[1]-y)*32, z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16((obj.x[2]-x)*32, (obj.y[2]-y)*32, z); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16((obj.x[3]-x)*32, (obj.y[3]-y)*32, z); glEnd(); } }