📄 graphics.c.svn-base
字号:
sceGuEnable(GU_TEXTURE_2D); sceGuClearColor(0); sceGuClear(GU_COLOR_BUFFER_BIT); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceDisplaySetFrameBuf(frameBuffer[displayBufferNumber], PSP_SCREEN_TEXTURE_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE); initialized = 1;}void initGraphics(int type, int mode){ pspType = type; if ( m33IsTVOutSupported(pspType) ) { pFlipScreen = flipScreenWithTVOutSupported; initGraphicsWithTVoutSupported(); setGraphicsVideoMode(mode); } else{ pFlipScreen = flipScreenWithoutTVOutSupported; initGraphicsWithoutTVoutSupported(); }}void disableGraphics(){ initialized = 0; videoMode = 0; pspType = 0;}void clearScreen() { sceGuClearColor(0); sceGuClear(GU_COLOR_BUFFER_BIT);}void flipScreen(){ pFlipScreen();}void flipScreenWithoutTVOutSupported() { if (!initialized) return; sceGuCopyImage(GU_PSM_8888, 0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, PSP_SCREEN_TEXTURE_WIDTH, globalCachedVramBase, 0, 0, PSP_SCREEN_TEXTURE_WIDTH, frameBuffer[displayBufferNumber]); sceGuTexSync(); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceDisplaySetFrameBuf(frameBuffer[displayBufferNumber], PSP_SCREEN_TEXTURE_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE); displayBufferNumber ^= 1;}void flipScreenWithTVOutSupported() { if (!initialized) return; pCopyVramToExtraMemory(); sceDisplayWaitVblankStart(); sceDisplaySetFrameBuf(frameBuffer[displayBufferNumber], PSP_TVOUT_TEXTURE_WIDTH, PSP_DISPLAY_PIXEL_FORMAT_8888, PSP_DISPLAY_SETBUF_IMMEDIATE); displayBufferNumber ^= 1;}//---------------BlitImageToScreen-----------------------//void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy){ pBlitImageToScreen(sx, sy, width, height, source, dx, dy);}void blitImageToScreenWithoutTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy){ if (!initialized) return; sceKernelDcacheWritebackInvalidateAll(); sceGuDisable(GU_BLEND); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuTexWrap(GU_CLAMP, GU_CLAMP); struct texture_subdivision_struct texture_subdivision; texture_subdivision_constructor(&texture_subdivision, width, height, 16, width, height, dx, dy); do { texture_subdivision_get(&texture_subdivision); guDrawSprite(&texture_subdivision); } while (texture_subdivision.output_last == 0); }void blitImageToScreenPSP(int sx, int sy, int width, int height, Image* source, int dx, int dy){ blitImageToScreenWithoutTVOut(sx, sy, width, height, source, dx, dy);} void blitImageToScreenTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy){ if (!initialized) return; sceKernelDcacheWritebackInvalidateAll(); sceGuDisable(GU_BLEND); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexWrap(GU_CLAMP, GU_CLAMP); struct texture_subdivision_struct texture_subdivision; texture_subdivision_constructor(&texture_subdivision, width, height, 16, width*tvWidth/PSP_SCREEN_WIDTH, height*tvHeight/PSP_SCREEN_HEIGHT, dx*tvWidth/PSP_SCREEN_WIDTH+tvLeft, dy*tvHeight/PSP_SCREEN_HEIGHT+tvTop); do { texture_subdivision_get(&texture_subdivision); guDrawSprite(&texture_subdivision); } while (texture_subdivision.output_last == 0); }//---------------BlitAlphaImageToScreen-----------------------//void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy){ pBlitAlphaImageToScreen(sx, sy, width, height, source, dx, dy);}void blitAlphaImageToScreenWithoutTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy){ if (!initialized) return; sceKernelDcacheWritebackInvalidateAll(); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuTexWrap(GU_CLAMP, GU_CLAMP); struct texture_subdivision_struct texture_subdivision; texture_subdivision_constructor(&texture_subdivision, width, height, 16, width, height, dx, dy); do { texture_subdivision_get(&texture_subdivision); guDrawSprite(&texture_subdivision); } while (texture_subdivision.output_last == 0); }void blitAlphaImageToScreenPSP(int sx, int sy, int width, int height, Image* source, int dx, int dy){ blitAlphaImageToScreenWithoutTVOut(sx, sy, width, height, source, dx, dy);}void blitAlphaImageToScreenTVOut(int sx, int sy, int width, int height, Image* source, int dx, int dy){ if (!initialized) return; sceKernelDcacheWritebackInvalidateAll(); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexWrap(GU_CLAMP, GU_CLAMP); struct texture_subdivision_struct texture_subdivision; texture_subdivision_constructor(&texture_subdivision, width, height, 16, width*tvWidth/PSP_SCREEN_WIDTH, height*tvHeight/PSP_SCREEN_HEIGHT, dx*tvWidth/PSP_SCREEN_WIDTH+tvLeft, dy*tvHeight/PSP_SCREEN_HEIGHT+tvTop); do { texture_subdivision_get(&texture_subdivision); guDrawSprite(&texture_subdivision); } while (texture_subdivision.output_last == 0); }//---------------CopyVramToExtraMemory-----------------------//void copyVramToExtraMemoryPSP(){ sceGuCopyImage(GU_PSM_8888, 0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, PSP_TVOUT_TEXTURE_WIDTH, globalCachedVramBase, 0, 0, PSP_TVOUT_TEXTURE_WIDTH, frameBuffer[displayBufferNumber]); sceGuTexSync(); sceGuFinish(); sceGuSync(0,0);}void copyVramToExtraMemoryTVOutInterlace(){ int i; void* s0 = globalCachedVramBase; void* d0 = frameBuffer[displayBufferNumber]; void* d1 = d0 + 262*PSP_TVOUT_480P_LINE_SIZE; for(i=0; i<240; i++) { sceGuCopyImage(GU_PSM_8888, 0, 0, PSP_TVOUT_WIDTH, 1, PSP_TVOUT_TEXTURE_WIDTH, s0, 0, 0, PSP_TVOUT_TEXTURE_WIDTH, d1); sceGuTexSync(); s0+=PSP_TVOUT_480P_LINE_SIZE; d1+=PSP_TVOUT_480P_LINE_SIZE; sceGuCopyImage(GU_PSM_8888, 0, 0, PSP_TVOUT_WIDTH, 1, PSP_TVOUT_TEXTURE_WIDTH, s0, 0, 0, PSP_TVOUT_TEXTURE_WIDTH, d0); sceGuTexSync(); s0+=PSP_TVOUT_480P_LINE_SIZE; d0+=PSP_TVOUT_480P_LINE_SIZE; } sceGuFinish(); sceGuSync(0,0);}void copyVramToExtraMemoryTVOutProgressive(){ sceGuCopyImage(GU_PSM_8888, 0, 0, PSP_TVOUT_WIDTH, PSP_TVOUT_HEIGHT, PSP_TVOUT_TEXTURE_WIDTH, globalCachedVramBase, 0, 0, PSP_TVOUT_TEXTURE_WIDTH, frameBuffer[displayBufferNumber]); sceGuTexSync(); sceGuFinish(); sceGuSync(0,0);}//---------------Image functions-----------------------//Image* createImage(int width, int height){ Image* image = (Image*) malloc_64(sizeof(Image)); if (!image) return NULL; image->imageWidth = width; image->imageHeight = height; image->textureWidth = getNextPower2(width); image->textureHeight = getNextPower2(height); image->data = (Color*) memalign(64, image->textureWidth * image->textureHeight * sizeof(Color)); if (!image->data) { free(image); return NULL; } memset(image->data, 0, image->textureWidth * image->textureHeight * sizeof(Color)); return image;}void freeImage(Image* image){ if (image != NULL) { if (image->data != NULL) free(image->data); free(image); }}void clearImage(Image* image, Color color){ int i; int size = image->textureWidth * image->textureHeight; Color* data = image->data; for (i = 0; i < size; i++, data++) *data = color;}void putPixelToImage(Image* image, Color color, int x, int y){ image->data[x + y * image->textureWidth] = color;}Color getPixelFromImage(Image* image, int x, int y){ return image->data[x + y * image->textureWidth];}void drawLineInImage(Image* image, Color color, int x0, int y0, int x1, int y1){ drawLine(x0, y0, x1, y1, color, image->data, image->textureWidth);}void fillImageRect(Image* image, Color color, int x0, int y0, int width, int height){ int skipX = image->textureWidth - width; int x, y; Color* data = image->data + x0 + y0 * image->textureWidth; for (y = 0; y < height; y++, data += skipX) { for (x = 0; x < width; x++, data++) *data = color; }}void fillImageEllipse(Image* image, Color color, int x0, int y0, int width, int height, int r) { int skipX = image->textureWidth - width; int x, y; Color* data = image->data + x0 + y0 * image->textureWidth; for (y = 0; y < height; y++, data += skipX) { for (x = 0; x < width; x++, data++) { if ( (x < r) && (y < r) && ((r-x)*(r-x)+(r-y)*(r-y) > r*r) ) continue; else if ( (x < r) && (y > height-r-1) && ((r-x)*(r-x)+(y-height+r+1)*(y-height+r+1) > r*r) ) continue; else if ( (x > width-r-1) && (y < r) && ((x-width+r+1)*(x-width+r+1)+(r-y)*(r-y) > r*r) ) continue; else if ( (x > width-r-1) && (y > height-r-1) && ((x-width+r+1)*(x-width+r+1)+(y-height+r+1)*(y-height+r+1) > r*r) ) continue; else *data = color; } }} void putImageToImage(Image* src, Image* dest, int dx, int dy, int dw, int dh) { int width = src->imageWidth > dw ? dw : src->imageWidth; int height = src->imageHeight > dh ? dh : src->imageHeight; int x, y; for(y = 0; y < height; y++ ) for( x = 0; x < width; x++ ) { dest->data[(dy+y)*dest->textureWidth + (dx+x)] = src->data[y*src->textureWidth+x]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -