Mercurial > hg > Members > kono > tree_dandy2
view sgoex.c @ 0:01387a2e419e
initial version
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Dec 2010 15:39:45 +0900 |
parents | |
children | 6541f0bebb81 |
line wrap: on
line source
/* スプライト管理関数 */ //#include<libps.h> #include <stdio.h> #include <SDL.h> #include "SDL_image.h" //#include "libps2.h" #include "SDL_opengl.h" #include "texture.h" #include "object.h" #include "tree_controll.h" #include "sgoex.h" #include "trace.h" #include "syokika.h" #include "LoadSprite.h" //extern void Back(GsOT * ot); extern void Draw_rectangle(void *obj); extern void draw_sprite(void *obj); #define OT_LENGTH 1 /* オーダリングテーブル */ #define MAXOBJ 320 /*スプライト表示上限 */ #define TRUE 1 #define FALSE 0 int count; /*オーダリングテーブル関連*/ //GsOT WorldOT[2]; //GsOT_TAG OTTags[2][1 << OT_LENGTH]; //PACKET GpuPacketArea[2][MAXOBJ * (20 + 4)]; //GsSPRITE *sp, sprite[MAXOBJ]; u_short tpage; //RECT rect; SDL_Rect rect; int nActiveBuff; /*ばふぁ */ int i; /* Multi-purpose */ //static int pageno; //static int padd; const int sgo_tpx[12] = { 0, 64, 128, 192, 256, 320, 0, 64, 128, 192, 256, 320 }; const int sgo_tpy[12] = { 0, 0, 0, 0, 0, 0, 256, 256, 256, 256, 256, 256 }; /* sgo.h 独自の変数形 */ SpriteTable sptable[DEFOBJ]; SpriteView spview[MAXOBJ]; #define IMAGE_ADJUSTMENT (0) /** * 一つの画像をpageno(page number)で区切るtexture_page_offsetで * pagenoに対応した領域のx,yを用意しておく。PlayStationではpageno * で区切る必要があったのだろうが、PS2では全く意味はなさない。 */ const struct texture_page_offset { int x; int y; } texpage_offset[] = { {0, 0}, {128 + IMAGE_ADJUSTMENT, 0}, {256 + IMAGE_ADJUSTMENT, 0}, {384 + IMAGE_ADJUSTMENT, 0}}; /*------------------------------------------------------------- 関数プロトタイプ ---------------------------------------------------------------*/ void Gdraw() { SDL_UpdateRect(screen, 0,0,0,0); } void DefSpriteEx(int number, short middlex, short middley) { sptable[number].mx = middlex; sptable[number].my = middley; } void SDL_GL_Enter2DMode() { // SDL_Surface *sc = SDL_GetVideoSurface(); /* Note, there may be other things you need to change, depending on how you have your OpenGL state set up. */ glPushAttrib(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); /* This allows alpha blending of 2D textures with the scene */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glViewport(0, 0, screen->w, screen->h); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } void SDL_GL_Leave2DMode() { glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); } static int power_of_two(int input) { int value = 1; while ( value < input ) { value <<= 1; } return value; } void DefSprite(int number, char *name, float w, float h, int color, OBJECT *obj) { SURFACE *surfaces; /* sptable[number].page = page; sptable[number].dx = x; sptable[number].dy = y; */ surfaces = search_node(obj, name); if(surfaces == NULL) { fprintf(stderr, "can't get node\n"); printf("%s", name); SDL_Quit(); exit(1); } sptable[number].w = w; sptable[number].h = h; sptable[number].color = (color & 32); sptable[number].mx = w / 2; sptable[number].my = h / 2; sptable[number].tex_w = power_of_two(sptable[number].w); sptable[number].tex_h = power_of_two(sptable[number].h); texMinX[number] = 0.0f; texMinY[number] = 0.0f; texMaxX[number] = (GLfloat)sptable[number].w / sptable[number].tex_w; texMaxY[number] = (GLfloat)sptable[number].h / sptable[number].tex_h; printf("texMaxX = %f, w = %d, tex_w = %d\n", texMaxX[number], sptable[number].w, sptable[number].tex_w); sptable[number].texture = surfaces->texture; } void PutSprite(int zorder, short x, short y, int number) { //static GLuint texture[250] = {0}; #if 0 /* sp = &sprite[zorder]; spview[zorder].extend = FALSE; sp->w = sptable[number].w; sp->h = sptable[number].h; sp->u = sptable[number].dx; sp->v = sptable[number].dy; sp->x = x; sp->y = y; sp->cx = 0; sp->cy = 480 + sptable[number].color; spview[zorder].no = number;*/ /* 表示するスプライトの番号の格納 */ #endif //SDL_GL_Enter2DMode(); glBindTexture(GL_TEXTURE_2D, (GLuint)sptable[number].texture); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(texMinX[number],texMinY[number]); glVertex2i((GLuint)x, (GLuint)y ); glTexCoord2f(texMinX[number],texMaxY[number]); glVertex2i((GLuint)x, (GLuint)(y+sptable[number].tex_h) ); glTexCoord2f(texMaxX[number],texMaxY[number]); glVertex2i((GLuint)(x+sptable[number].tex_w), (GLuint)(y+sptable[number].tex_h)); glTexCoord2f(texMaxX[number],texMinY[number]); glVertex2i((GLuint)(x+sptable[number].tex_w), (GLuint)y); glEnd(); glDisable(GL_BLEND); //SDL_GL_Leave2DMode(); } void PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) { SpriteTable *m = &sptable[number]; x -= m->w; y -= m->h; SDL_GL_Enter2DMode(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, (GLuint)sptable[number].texture); glTranslatef(x + m->w/2, y + m->h/2, 0.0); glRotatef(angle, 0.0, 0.0, 1.0); glScalef(scalex, scaley, 1.0); glBegin(GL_TRIANGLE_STRIP); { glTexCoord2f(texMinX[number], texMinY[number]); glVertex2i(-m->w/2, -m->h/2); glTexCoord2f(texMaxX[number], texMinY[number]); glVertex2i( m->w/2, -m->h/2); glTexCoord2f(texMinX[number], texMaxY[number]); glVertex2i(-m->w/2, m->h/2); glTexCoord2f(texMaxX[number], texMaxY[number]); glVertex2i( m->w/2, m->h/2); } glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); SDL_GL_Leave2DMode(); // SDL_GL_SwapBuffers(); } /*void PutSpriteEx(int zorder, short scalex, short scaley, long rotate) { sp = &sprite[zorder]; spview[zorder].extend = TRUE; sp->mx = sptable[spview[zorder].no].mx; sp->my = sptable[spview[zorder].no].my; sp->scalex = scalex; sp->scaley = scaley; sp->rotate = rotate; }*/ void init_tim(u_long addr) { //RECT rect; /* SDL_Rect rect; GsIMAGE image; GsGetTimInfo((unsigned int *) (addr + 4), &image); rect.x = image.px; rect.y = image.py; rect.w = image.pw; rect.h = image.ph; LoadImage(&rect, image.pixel); DrawSync(0); rect.x = image.cx; rect.y = image.cy; rect.w = image.cw; rect.h = image.ch; LoadImage(&rect, image.clut); DrawSync(0); */ } struct SGO_PAD pad[2]; #ifdef ENABLE_TRACEMODE extern int runmode; #endif //ENABLE_TRACEMODE /* コントローラ状態の読み込み */ void Pad(SDL_Joystick *joy) { Sint16 axis; SDL_JoystickUpdate(); if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) pad[0].k0++; else pad[0].k0=0; if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) pad[0].k1++; else pad[0].k1=0; if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) pad[0].k3++; else pad[0].k3=0; if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) pad[0].k4++; else pad[0].k4=0; if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) pad[0].l1++; else pad[0].l1=0; if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) pad[0].r1++; else pad[0].r1=0; if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) pad[0].l2++; else pad[0].l2=0; if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) pad[0].r2++; else pad[0].r2=0; if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) pad[0].st++; else pad[0].st=0; if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) pad[0].se++; else pad[0].se=0; if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) pad[0].l3++; else pad[0].l3=0; if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) pad[0].r3++; else pad[0].r3=0; //x axis=SDL_JoystickGetAxis(joy,0); if(axis>=3200){ pad[0].left=0; pad[0].right++; } else if(axis<=-3200){ pad[0].right=0; pad[0].left++; } else { pad[0].right=0; pad[0].left=0; } //y axis=SDL_JoystickGetAxis(joy,1); if(axis>=3200){ pad[0].up=0; pad[0].down++; } else if(axis<=-3200){ pad[0].down=0; pad[0].up++; } else { pad[0].down=0; pad[0].up=0; } if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && (pad[0].l2 != 0) && (pad[0].r2 != 0) && (pad[0].st != 0) && (pad[0].se != 0)) { pad[0].quit = 1; } else { pad[0].quit = 0; } } void keybord() { SDL_PumpEvents(); Uint8 *keys = SDL_GetKeyState(NULL); if (keys[SDLK_UP]) { pad[0].up++; } else { pad[0].up = 0; } if (keys[SDLK_DOWN]) { pad[0].down++; } else { pad[0].down = 0; } if (keys[SDLK_RIGHT]) { pad[0].right++; } else { pad[0].right = 0; } if (keys[SDLK_LEFT]) { pad[0].left++; } else { pad[0].left = 0; } if (keys[SDLK_a]) { pad[0].k0++; } else { pad[0].k0 = 0; } if (keys[SDLK_z]) { pad[0].k1++; } else { pad[0].k1 = 0; } if (keys[SDLK_s]) { pad[0].k3++; } else { pad[0].k3 = 0; } if (keys[SDLK_x]) { pad[0].k4++; } else { pad[0].k4 = 0; } if (keys[SDLK_r]) { pad[0].r2++; } else { pad[0].r2 = 0; } if (keys[SDLK_e]) { pad[0].r1++; } else { pad[0].r1 = 0; } if (keys[SDLK_w]) { pad[0].l1++; } else { pad[0].l1 = 0; } if (keys[SDLK_q]) { pad[0].l2++; } else { pad[0].l2 = 0; } // START ボタンは Return が似合う気がする //if(keys[SDLK_1]) if (keys[SDLK_RETURN]) { pad[0].st++; } else { pad[0].st = 0; } if (keys[SDLK_2]) { pad[0].se++; } else { pad[0].se = 0; } if (keys[SDLK_ESCAPE]) { SDL_Quit(); exit(1); //pad[0].st = 1; //pad[0].se = 1; } if (keys[SDLK_0]) { pad[0].quit = 1; } else { pad[0].quit = 0; } } /*! \brief PNGシステムの初期化 */ /* void *init_png(char *png_file) { TEXTURE *tex[1]; tex[0] = read_png_file0(png_file, 1); if (tex[0] == NULL) { fprintf(stderr, "failed to read a texture data. \n"); goto INIT_PNG_FAILED; } if (load_textures(1, tex) < 0) { fprintf(stderr, "failed to load a texture to GS-VRAM. \n"); goto INIT_PNG_FAILED; } return tex[0]; fflush(stderr); return NULL; } */