void SeaActor::renderSea(int xMin, int xMax, int zMin, int zMax, int inc, bool trick) { int s = 900; int vel = 7; int zstart = sc->time / vel + zMin; //6 quad/s int zend= sc->time / vel + zMax; //6 quad/s int ofs = sc->time * s / vel; int r = 80; int b = 240; for(int z = zstart; z < zend; z+=inc) { glBegin(GL_QUAD_STRIP); int old1 = gety(xMin, z); int old2 = gety(xMin, z+inc); int oldc1 = getc(xMin, z); int oldc2 = getc(xMin, z+inc); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*inc), inttot16(0)); glColor3b(r, oldc1, b); glVertex3v16((xMin+0)*s, old1, -(z+0)*s+ofs); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*inc), inttot16(64*inc)); glColor3b(r, oldc2, b); glVertex3v16((xMin+0)*s, old2, -(z+inc)*s+ofs); bool tex = false; for(int x = xMin; x < xMax; x+=inc) { int new1 = gety(x+inc, z); int new2; if(trick && z == zend-1 && (x/inc)%2 == 0) new2 = (old2+gety(x+inc*2, z+inc))/2; else new2 = gety(x+inc, z+inc); int newc1 = getc(x+inc, z); int newc2 = getc(x+inc, z+inc); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*tex*inc), inttot16(0)); glColor3b(r, newc1, b); glVertex3v16((x+inc)*s, new1, -(z+0)*s+ofs); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64*tex*inc), inttot16(64*inc)); glColor3b(r, newc2, b); glVertex3v16((x+inc)*s, new2, -(z+inc)*s+ofs); tex = !tex; old1 = new1; old2 = new2; oldc1 = newc1; oldc2 = newc2; } glEnd(); } }
void renderChar(char c, f32 x, f32 y, f32 sz) { sz += sz/2; int xc = (c % 32) * 8; int yc = (c / 32) * 8; setTexture(4); glBegin(GL_QUAD); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc),inttot16(yc+8)-1); glVertex3f32(x-sz, y-sz, 0); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc+8)-1,inttot16(yc+8)-1); glVertex3f32(x+sz, y-sz, 0); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc+8)-1,inttot16(yc)); glVertex3f32(x+sz, y+sz, 0); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc),inttot16(yc)); glVertex3f32(x-sz, y+sz, 0); glEnd(); }
void drawLogo(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof32(inttof32(0), inttof32(255), inttof32(191), inttof32(0), -inttof32(1), inttof32(1)); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); applyMTL(logoMain); glScalef32(inttof32(256),inttof32(128),inttof32(1)); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(inttof32(0), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(256), inttot16(0)); glVertex3v16(inttof32(1), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(256), inttot16(128)); glVertex3v16(inttof32(1), inttof32(1), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(128)); glVertex3v16(inttof32(0), inttof32(1), inttof32(0)); glPopMatrix(1); glPushMatrix(); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); applyMTL(logoRotate); glTranslate3f32(inttof32(90+32),inttof32(28+32),-inttof32(1)/16); glRotateZi(logoAngle+=32); glTranslate3f32(-inttof32(32),-inttof32(32),0); glScalef32(inttof32(64),inttof32(64),inttof32(1)); glBegin(GL_QUADS); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(0)); glVertex3v16(inttof32(0), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(0)); glVertex3v16(inttof32(1), inttof32(0), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(64), inttot16(64)); glVertex3v16(inttof32(1), inttof32(1), inttof32(0)); GFX_TEX_COORD = TEXTURE_PACK(inttot16(0), inttot16(64)); glVertex3v16(inttof32(0), inttof32(1), inttof32(0)); glPopMatrix(1); }
#include "textures.h" #include "introtext.h" #include "texs.h" int textureIDS[20]; //texture coordinates const u32 uv[] = { TEXTURE_PACK(inttot16(64), 0), TEXTURE_PACK(inttot16(64),inttot16(64)), TEXTURE_PACK(0, inttot16(64)), TEXTURE_PACK(0,0) }; void renderChar(char c, f32 x, f32 y, f32 sz) { sz += sz/2; int xc = (c % 32) * 8; int yc = (c / 32) * 8; setTexture(4); glBegin(GL_QUAD); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc),inttot16(yc+8)-1); glVertex3f32(x-sz, y-sz, 0); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc+8)-1,inttot16(yc+8)-1); glVertex3f32(x+sz, y-sz, 0); GFX_TEX_COORD = TEXTURE_PACK(inttot16(xc+8)-1,inttot16(yc)); glVertex3f32(x+sz, y+sz, 0);
void logo() { glResetMatrixStack(); glMatrixMode(GL_PROJECTION); gluPerspective(20, 256.0 / 192.0, 0.1, 40); gluLookAt( 0.0, .55, 0.0 , //camera possition 0.0, 0.0, 0.0, //look at 0.0, 0.0, -1.0); //up glLight(0, RGB15(31,31,31), 0, floattov10(1.0)-1, 0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glMaterialf(GL_AMBIENT, RGB15(8,8,8)); glMaterialf(GL_DIFFUSE, RGB15(31,31,31)); glMaterialf(GL_SPECULAR, RGB15(31,31,31)); glMaterialf(GL_EMISSION, RGB15(8,8,8)); glMaterialShinyness(); glPolyFmt( POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 ); glGenTextures(1, &logotex); glBindTexture(0, logotex); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD , (u8*)billkuker_bmp_bin); glBindTexture(0, logotex); glBegin(GL_QUAD); glNormal(NORMAL_PACK(0,inttov10(1),0)); glTexCoord1i(TEXTURE_PACK(0,0)); glVertex3v16(floattov16(-0.5), floattov16(-0.5), floattov16(0.5) ); glTexCoord1i(TEXTURE_PACK(inttot16(256), inttot16(0))); glVertex3v16(floattov16(0.5), floattov16(-0.5), floattov16(0.5) ); glTexCoord1i(TEXTURE_PACK(inttot16(256),inttot16(256))); glVertex3v16(floattov16(0.5), floattov16(-0.5), floattov16(-0.5) ); glTexCoord1i(TEXTURE_PACK(0, inttot16(256))); glVertex3v16(floattov16(-0.5), floattov16(-0.5), floattov16(-0.5) ); glEnd(); glFlush(0); playGenericSound(down_raw, down_raw_size); playGenericSound(up_raw, up_raw_size); swiWaitForVBlank(); iprintf("Press any button"); while( !keysHeld() ) scanKeys(); glResetTextures(); iprintf("\x1b[2J"); }
int main() { int textureID; float rotateX = 0.0; float rotateY = 0.0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // initialize gl glInit(); //enable textures glEnable(GL_TEXTURE_2D); // enable antialiasing glEnable(GL_ANTIALIAS); // setup the rear plane glClearColor(0,0,0,31); // BG must be opaque for AA to work glClearPolyID(63); // BG must have a unique polygon ID for AA to work glClearDepth(0x7FFF); //this should work the same as the normal gl call glViewport(0,0,255,191); vramSetBankA(VRAM_A_TEXTURE); glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin); //any floating point gl call is being converted to fixed prior to being implemented glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 40); gluLookAt( 0.0, 0.0, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up while(1) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); //move it away from the camera glTranslate3f32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMaterialf(GL_AMBIENT, RGB15(16,16,16)); glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(16,16,16)); //ds uses a table for shinyness..this generates a half-ass one glMaterialShinyness(); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK); 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; glBindTexture(0, textureID); //draw the obj glBegin(GL_QUAD); glNormal(NORMAL_PACK(0,inttov10(-1),0)); GFX_TEX_COORD = (TEXTURE_PACK(0, inttot16(128))); glVertex3v16(floattov16(-0.5), floattov16(-0.5), 0 ); GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128),inttot16(128))); glVertex3v16(floattov16(0.5), floattov16(-0.5), 0 ); GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128), 0)); glVertex3v16(floattov16(0.5), floattov16(0.5), 0 ); GFX_TEX_COORD = (TEXTURE_PACK(0,0)); glVertex3v16(floattov16(-0.5), floattov16(0.5), 0 ); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); } return 0; }//end main
//polys u8 CubeFaces[] = { 3,2,1,0, 0,1,5,4, 1,2,6,5, 2,3,7,6, 3,0,4,7, 5,6,7,4 }; //texture coordinates u32 uv[] = { TEXTURE_PACK(inttot16(128), 0), TEXTURE_PACK(inttot16(128),inttot16(128)), TEXTURE_PACK(0, inttot16(128)), TEXTURE_PACK(0,0) }; u32 normals[] = { NORMAL_PACK(0,floattov10(-.97),0), NORMAL_PACK(0,0,floattov10(.97)), NORMAL_PACK(floattov10(.97),0,0), NORMAL_PACK(0,0,floattov10(-.97)), NORMAL_PACK(floattov10(-.97),0,0), NORMAL_PACK(0,floattov10(.97),0) };
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(); } }
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); } }