int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; GPU_Image* image = GPU_LoadImage("data/test.bmp"); if(image == NULL) return -1; startTime = SDL_GetTicks(); frameCount = 0; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } GPU_Clear(screen); GPU_BlitTransform(image, NULL, screen, screen->w/2, screen->h/2, 360*sin(SDL_GetTicks()/2000.0f), 2.5*sin(SDL_GetTicks()/1000.0f), 2.5*sin(SDL_GetTicks()/1200.0f)); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); } GPU_Quit(); return 0; }
/* Main program : Initialize the system and start the first task */ int main (void) { Initialize_Button(USER); Initialize_Button(TAMPER); Initialize_Led(LED1); Initialize_Led(LED2); Initialize_Led(LED3); Initialize_Led(LED4); Initialize_Led(LED5); Initialize_Led(LED6); Initialize_Led(LED7); Initialize_Led(LED8); Turn_Led(LED1,ON); GPU_Init(); JOY_Init(); initSD(&fs32); wait(1000000); while(1) { // Start the task menu allow to choose the program // - GIF unicorn // - Street of rage // - Zelda os_sys_init (taskMenu); } } //Fin main
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) { INFO_LOG(BOOT, "PPSSPP %s", PPSSPP_GIT_VERSION); coreParameter = coreParam; coreParameter.errorString = ""; if (g_Config.bSeparateCPUThread) { Core_ListenShutdown(System_Wake); CPU_SetState(CPU_THREAD_PENDING); cpuThread = new std::thread(&CPU_RunLoop); cpuThread->detach(); CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsReady); } else { CPU_Init(); } bool success = coreParameter.fileToStart != ""; *error_string = coreParameter.errorString; if (success) { success = GPU_Init(); if (!success) { PSP_Shutdown(); *error_string = "Unable to initialize rendering engine."; } } return success; }
int main(int argc, char* argv[]) { printRenderers(); GPU_Target* screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); int i = 1; while(i > 0) { if(i == 1) i = do_interleaved(screen); else if(i == 2) i = do_separate(screen); else if(i == 3) i = do_attributes(screen); else i = 0; } GPU_Quit(); return i; }
void gpuInit(void) { colorBuf = vramAlloc(400*240*4); depthBuf = vramAlloc(400*240*4); cmdBuf = linearAlloc(0x40000*4); GPU_Init(NULL); GPU_Reset(NULL, cmdBuf, 0x40000); }
int sf2d_init_advanced(int gpucmd_size, int temppool_size) { if (sf2d_initialized) return 0; gpu_fb_addr = vramMemAlign(400*240*8, 0x100); gpu_depth_fb_addr = vramMemAlign(400*240*8, 0x100); gpu_cmd = linearAlloc(gpucmd_size * 4); pool_addr = linearAlloc(temppool_size); pool_size = temppool_size; gpu_cmd_size = gpucmd_size; //gfxInitDefault(); GPU_Init(NULL); //gfxSet3D(false); GPU_Reset(NULL, gpu_cmd, gpucmd_size); //Setup the shader dvlb = DVLB_ParseFile((u32 *)shader_vsh_shbin, shader_vsh_shbin_size); shaderProgramInit(&shader); shaderProgramSetVsh(&shader, &dvlb->DVLE[0]); //Get shader uniform descriptors projection_desc = shaderInstanceGetUniformLocation(shader.vertexShader, "projection"); shaderProgramUse(&shader); matrix_init_orthographic(ortho_matrix_top, 0.0f, 400.0f, 0.0f, 240.0f, 0.0f, 1.0f); matrix_init_orthographic(ortho_matrix_bot, 0.0f, 320.0f, 0.0f, 240.0f, 0.0f, 1.0f); matrix_gpu_set_uniform(ortho_matrix_top, projection_desc); //Register the apt callback hook //aptHook(&apt_hook_cookie, apt_hook_func, NULL); vblank_wait = 1; current_fps = 0.0f; frames = 0; last_time = osGetTime(); cur_screen = GFX_TOP; cur_side = GFX_LEFT; GPUCMD_Finalize(); GPUCMD_FlushAndRun(); gspWaitForP3D(); sf2d_pool_reset(); sf2d_initialized = 1; return 1; }
int main(int argc, char* argv[]) { GPU_Target* screen; screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; main_loop(screen); GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { printRenderers(); GPU_Target* screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); Uint32 startTime = SDL_GetTicks(); long frameCount = 0; Uint8 done = 0; SDL_Event event; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } GPU_Clear(screen); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_Quit(); return 0; }
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) { INFO_LOG(HLE, "PPSSPP %s", PPSSPP_GIT_VERSION); coreParameter = coreParam; coreParameter.errorString = ""; if (g_Config.bSeparateCPUThread) { CPU_SetState(CPU_THREAD_PENDING); cpuThread = new std::thread(&CPU_RunLoop); CPU_WaitStatus(&CPU_IsReady); } else { CPU_Init(); } bool success = coreParameter.fileToStart != ""; *error_string = coreParameter.errorString; if (success) { GPU_Init(); } return success; }
bool PSP_InitUpdate(std::string *error_string) { if (pspIsInited || !pspIsIniting) { return true; } if (g_Config.bSeparateCPUThread && !CPU_IsReady()) { return false; } bool success = coreParameter.fileToStart != ""; *error_string = coreParameter.errorString; if (success) { success = GPU_Init(); if (!success) { PSP_Shutdown(); *error_string = "Unable to initialize rendering engine."; } } pspIsInited = success; pspIsIniting = false; return true; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; int mx, my; GPU_Image* image; GPU_Target* target; SDL_Color c; image = GPU_LoadImage("data/test.bmp"); if(image == NULL) return -1; target = GPU_LoadTarget(image); startTime = SDL_GetTicks(); frameCount = 0; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } SDL_GetMouseState(&mx, &my); c = GPU_GetPixel(target, mx - 50, my - 50); GPU_ClearRGBA(screen, c.r, c.g, c.b, GET_ALPHA(c)); GPU_Blit(image, NULL, screen, image->w/2 + 50, image->h/2 + 50); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); } GPU_Quit(); return 0; }
int Screen_Init(int coreid) { MainScreen.gpu = GPU_Init(0); SubScreen.gpu = GPU_Init(1); return 0; }
bool gpuInit() { if(!serviceRequire("gfx")) { return false; } dirtyState = 0xFFFFFFFF; dirtyTexEnvs = 0xFFFFFFFF; dirtyTextures = 0xFFFFFFFF; clearColor = 0; clearDepth = 0; viewportScreen = TOP_SCREEN; viewportX = 0; viewportY = 0; viewportWidth = 240; viewportHeight = 400; scissorMode = SCISSOR_DISABLE; scissorX = 0; scissorY = 0; scissorWidth = 240; scissorHeight = 400; depthNear = 0; depthFar = 1; cullMode = CULL_NONE; stencilEnable = false; stencilFunc = TEST_ALWAYS; stencilRef = 0; stencilMask = 0xFF; stencilReplace = 0; stencilFail = OP_KEEP; stencilZFail = OP_KEEP; stencilZPass = OP_KEEP; blendRed = 0; blendGreen = 0; blendBlue = 0; blendAlpha = 0; blendColorEquation = BLEND_ADD; blendAlphaEquation = BLEND_ADD; blendColorSrc = FACTOR_SRC_ALPHA; blendColorDst = FACTOR_ONE_MINUS_SRC_ALPHA; blendAlphaSrc = FACTOR_SRC_ALPHA; blendAlphaDst = FACTOR_ONE_MINUS_SRC_ALPHA; alphaEnable = false; alphaFunc = TEST_ALWAYS; alphaRef = 0; depthEnable = false; depthFunc = TEST_GREATER; componentMask = GPU_WRITE_ALL; activeShader = NULL; texEnv[0].rgbSources = TEXENV_SOURCES(SOURCE_TEXTURE0, SOURCE_PRIMARY_COLOR, SOURCE_PRIMARY_COLOR); texEnv[0].alphaSources = TEXENV_SOURCES(SOURCE_TEXTURE0, SOURCE_PRIMARY_COLOR, SOURCE_PRIMARY_COLOR); texEnv[0].rgbOperands = TEXENV_OPERANDS(0, 0, 0); texEnv[0].alphaOperands = TEXENV_OPERANDS(0, 0, 0); texEnv[0].rgbCombine = COMBINE_MODULATE; texEnv[0].alphaCombine = COMBINE_MODULATE; texEnv[0].constantColor = 0xFFFFFFFF; for(u8 env = 1; env < TEX_ENV_COUNT; env++) { texEnv[env].rgbSources = TEXENV_SOURCES(SOURCE_PREVIOUS, SOURCE_PRIMARY_COLOR, SOURCE_PRIMARY_COLOR); texEnv[env].alphaSources = TEXENV_SOURCES(SOURCE_PREVIOUS, SOURCE_PRIMARY_COLOR, SOURCE_PRIMARY_COLOR); texEnv[env].rgbOperands = TEXENV_OPERANDS(0, 0, 0); texEnv[env].alphaOperands = TEXENV_OPERANDS(0, 0, 0); texEnv[env].rgbCombine = COMBINE_REPLACE; texEnv[env].alphaCombine = COMBINE_REPLACE; texEnv[env].constantColor = 0xFFFFFFFF; } for(u8 unit = 0; unit < TEX_UNIT_COUNT; unit++) { activeTextures[unit] = NULL; } enabledTextures = 0; u32 gpuCmdSize = 0x40000; u32* gpuCmd = (u32*) linearAlloc(gpuCmdSize * 4); GPU_Init(NULL); GPU_Reset(NULL, gpuCmd, gpuCmdSize); GPUCMD_SetBufferOffset(0); return true; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { GPU_Image* image; float x, y; float velx, vely; float dt; Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; image = GPU_LoadImage("data/test3.png"); if (image == NULL) return -1; x = 0; y = 0; velx = 50.0f; vely = 70.0f; dt = 0.010f; startTime = SDL_GetTicks(); frameCount = 0; done = 0; while (!done) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) done = 1; else if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } x += velx*dt; y += vely*dt; if (x < 0) { x = 0; velx = -velx; } else if (x + image->w > screen->w) { x = screen->w - image->w; velx = -velx; } if (y < 0) { y = 0; vely = -vely; } else if (y + image->h > screen->h) { y = screen->h - image->h; vely = -vely; } GPU_Clear(screen); GPU_Blit(image, NULL, screen, 50, 50); GPU_Blit(image, NULL, screen, 150, 50); GPU_Blit(image, NULL, screen, 350, 250); GPU_SetBlending(image, 1); GPU_SetRGBA(image, 255, 100, 255, 127.5f + 127.5f*sin(SDL_GetTicks() / 1000.0f)); GPU_Blit(image, NULL, screen, x, y); GPU_SetRGBA(image, 255, 255, 255, 255); GPU_SetBlending(image, 0); GPU_Flip(screen); frameCount++; if (frameCount % 500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime)); GPU_FreeImage(image); } GPU_Quit(); return 0; }
int main(int argc, char **argv) { SDL_Surface *screen; SDL_Event event; int quit = 0; SDL_Rect dest; dest.x = 62; dest.y = 0; struct GPU_Glsprite *glsprite; struct GPU_Glsprite *glsprite2; struct GPU_GlShader *shader; struct GPU_Framebuffer *buffer; framebuffer *buffer2 = new framebuffer; // 1- inicialize SDL if(SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); //exit(-1); return 0; } atexit(SDL_Quit); //2-Set Opengl attrs SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //3- initialize screen if((screen = SDL_SetVideoMode(800, 600, 0, SDL_OPENGL | SDL_HWSURFACE)) == 0) { fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError()); // exit(-1); return 0; } GPU_Init(); // glViewport(0, 0, 800, 600); //5- continue initializing opengl glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glOrtho(0, 800, 0, 600, -1, 1); //gluOrtho2D(-1, 1, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); // initialize the glsprite SDL_Surface *img = SDL_LoadBMP("terreno.bmp"); // SDL_Color colorkey = {0xFF, 0x00, 0xFF, 0}; if ( (glsprite = (GPU_InitGlsprite(img, 0, TARGET_TEXTURE_2D | FORMAT_RGB | TYPE_UNSIGNED_BYTE))) == 0 ) { fprintf(stderr, "Error loading the image file!\n"); exit(-1); } buffer2->addTexture( TEXTURE_2D, RGB, INTERNAL_RGB, 0, 512, 512); buffer2->initialize(); shader = GPU_InitShader(0, invertFS); GPU_BindShader(shader); GLcharARB *log; log = GPU_GetShaderLog(shader); printf(log); free(log); // GPU_SendUniform1f(shader, "Alpha", 0.2f); GPU_SendTexture(shader, "texture", 0); //GPU_SendUniform1f(shader, "desaturate", 1.0); //GPU_SendUniform1f(shader, "toning", 1.0); //GPU_SendUniform1f(shader, "texsize", 512.0); //GPU_SendUniform1f(shader, "scale", 2.0); //GPU_SendUniform1f(shader, "numtiles", 40000.0); //GPU_SendUniform1f(shader, "edgewidth", 0.1); //GPU_BlitSpriteOnFramebuffer(buffer, glsprite, &dest); buffer2->bind(); { glViewport(0, 0, 512, 512); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, glsprite->texID); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f); glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f); glEnd(); glPopMatrix(); } buffer2->unbind(); GPU_UnbindShader(); SDL_Surface *surface; Uint32 rmask, gmask, bmask, amask; /* SDL interprets each pixel as a 32-bit number, so our masks must depend on the endianness (byte order) of the machine */ #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif surface = SDL_CreateRGBSurface(SDL_HWSURFACE, 512, 512, 24, rmask, gmask, bmask, 0); if(surface == NULL) { return 0; } buffer2->bind(); { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glReadPixels(0, 0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); } buffer2->unbind(); //img2 = GPU_FramebufferToSurface(buffer); SDL_SaveBMP(surface, "TerrainWithShader.bmp" ); /* if ( (glsprite2 = (GPU_InitGlsprite(img2, 0, TARGET_TEXTURE_2D | FORMAT_RGB | TYPE_UNSIGNED_BYTE))) == 0 ) { fprintf(stderr, "Error loading the image file 2!\n"); exit(-1); } */ // GPU_FreeFramebuffer(buffer); // free(buffer); //buffer2 = GPU_FramebufferInit( TARGET_TEXTURE_2D | FORMAT_RGB | TYPE_UNSIGNED_BYTE, img->w, img->h ); /* shader2 = GPU_ShaderInit(0, brightnessShader); GPU_SendTexture(shader2, "texture", 0); //GPU_AddShader(buffer, shader2); glUseProgramObjectARB( shader2->program); GPU_BlitOnFramebuffer(buffer, glsprite2, &dest); glUseProgramObjectARB( 0); if ( (glsprite3 = (GPU_AllocGlsprite(GPU_FramebufferToSurface(buffer), 0, TARGET_TEXTURE_2D | FORMAT_RGB | TYPE_UNSIGNED_BYTE))) == 0 ) { fprintf(stderr, "Error loading the image file!\n"); exit(-1); } /* main loop */ while (!quit) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: quit = 1; break; case SDL_KEYDOWN: switch( event.key.keysym.sym ){ case SDLK_ESCAPE: case SDLK_q: quit = 1; break; case SDLK_F1: SDL_WM_ToggleFullScreen(screen); break; default: break; } } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GPU_DrawGlsprite(glsprite, 0); // GPU_BlitFramebufferOnScreen(buffer, glsprite, &dest); glFlush(); SDL_GL_SwapBuffers(); } // SDL_SaveBMP(GPU_FramebufferToSurface(buffer), "buffer2shaders.bmp" ); // quit GPU_FreeGlsprite(glsprite); delete buffer2; GPU_FreeShader(shader); SDL_Quit(); return 0; }
int main(int argc, char* argv[]) { printRenderers(); GPU_Target* screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); int numImages = 0; GPU_Image* images[argc-1]; int i; for(i = 1; i < argc; i++) { images[numImages] = GPU_LoadImage(argv[i]); if(images[numImages] != NULL) numImages++; } Uint8* keystates = SDL_GetKeyState(NULL); GPU_Camera camera = GPU_GetDefaultCamera(); float dt = 0.010f; Uint8 done = 0; SDL_Event event; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } if(keystates[KEY_UP]) { camera.y -= 200*dt; } else if(keystates[KEY_DOWN]) { camera.y += 200*dt; } if(keystates[KEY_LEFT]) { camera.x -= 200*dt; } else if(keystates[KEY_RIGHT]) { camera.x += 200*dt; } if(keystates[KEY_MINUS]) { camera.zoom -= 1.0f*dt; } else if(keystates[KEY_EQUALS]) { camera.zoom += 1.0f*dt; } GPU_ClearRGBA(screen, 255, 255, 255, 255); GPU_SetCamera(screen, &camera); float x = 100; float y = 100; for(i = 0; i < numImages; i++) { float x_scale = 150.0f/images[i]->w; float y_scale = 150.0f/images[i]->h; GPU_BlitScale(images[i], NULL, screen, x, y, x_scale, y_scale); x += 200; if((i+1)%4 == 0) { x = 100; y += 200; } } GPU_Flip(screen); SDL_Delay(10); } for(i = 0; i < numImages; i++) { GPU_FreeImage(images[i]); } GPU_Quit(); return 0; }
int main() { int i, x, y; touchPosition lastTouch; u32 repeatkeys = 0; int repeatstate = 0; int repeatcount = 0; running = 0; pause = 0; exitemu = 0; PPU_Init(); srvInit(); aptInit(); aptOpenSession(); APT_SetAppCpuTimeLimit(NULL, 30); // enables syscore usage aptCloseSession(); gfxInit(); hidInit(NULL); fsInit(); GPU_Init(NULL); gpuCmdSize = 0x40000; gpuCmd = (u32*)linearAlloc(gpuCmdSize*4); GPU_Reset(gxCmdBuf, gpuCmd, gpuCmdSize); shader = SHDR_ParseSHBIN((u32*)blarg_shbin, blarg_shbin_size); GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201); gfxSwapBuffersGpu(); UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL)); BorderTex = (u32*)linearAlloc(512*256*4); MainScreenTex = (u32*)linearAlloc(512*256*4); SubScreenTex = (u32*)linearAlloc(512*256*4); BrightnessTex = (u8*)linearAlloc(8*256); borderVertices = (float*)linearAlloc(5*3 * 2 * sizeof(float)); screenVertices = (float*)linearAlloc(7*3 * 2 * sizeof(float)); float* fptr = &vertexList[0]; for (i = 0; i < 5*3*2; i++) borderVertices[i] = *fptr++; for (i = 0; i < 7*3*2; i++) screenVertices[i] = *fptr++; sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FSUSER_OpenArchive(NULL, &sdmcArchive); if (!LoadBorder("/blargSnesBorder.bmp")) CopyBitmapToTexture(defaultborder, BorderTex, 400, 240, 0xFF, 0, 64, true); CopyBitmapToTexture(screenfill, PPU_MainBuffer, 256, 224, 0, 16, 64, false); memset(PPU_SubBuffer, 0, 256*256*4); memset(PPU_Brightness, 0xFF, 224); UI_Switch(&UI_ROMMenu); svcCreateEvent(&SPCSync, 0); aptSetupEventHandler(); APP_STATUS status; while((status = aptGetStatus()) != APP_EXITING) { if(status == APP_RUNNING) { svcSignalEvent(SPCSync); hidScanInput(); u32 press = hidKeysDown(); u32 held = hidKeysHeld(); u32 release = hidKeysUp(); GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0); RenderTopScreen(); GPUCMD_Finalize(); GPUCMD_Run(gxCmdBuf); if (running) { // emulate CPU_Run(); // runs the SNES for one frame. Handles PPU rendering. // SRAM autosave check // TODO: also save SRAM under certain circumstances (pausing, returning to home menu, etc) framecount++; if (!(framecount & 7)) SNES_SaveSRAM(); } else { // update UI if (held & KEY_TOUCH) { hidTouchRead(&lastTouch); UI_Touch(true, lastTouch.px, lastTouch.py); held &= ~KEY_TOUCH; } else if (release & KEY_TOUCH) { UI_Touch(false, lastTouch.px, lastTouch.py); release &= ~KEY_TOUCH; } if (press) { UI_ButtonPress(press); // key repeat repeatkeys = press & (KEY_UP|KEY_DOWN|KEY_LEFT|KEY_RIGHT); repeatstate = 1; repeatcount = 15; } else if (held == repeatkeys) { repeatcount--; if (!repeatcount) { repeatcount = 7; if (repeatstate == 2) UI_ButtonPress(repeatkeys); else repeatstate = 2; } } } UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL)); UI_Render(); /*GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0); RenderTopScreen(); GPUCMD_Finalize(); GPUCMD_Run(gxCmdBuf);*/ // flush the bottomscreen cache while the PICA200 is busy rendering GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x38400); // wait for the PICA200 to finish drawing gspWaitForP3D(); // copy new screen textures // SetDisplayTransfer with flags=2 converts linear graphics to the tiled format used for textures GX_SetDisplayTransfer(gxCmdBuf, PPU_MainBuffer, 0x01000200, MainScreenTex, 0x01000200, 0x2); gspWaitForPPF(); GX_SetDisplayTransfer(gxCmdBuf, PPU_SubBuffer, 0x01000200, SubScreenTex, 0x01000200, 0x2); gspWaitForPPF(); // copy brightness. // TODO do better u8* bptr = BrightnessTex; for (i = 0; i < 224;) { u32 pixels = *(u32*)&PPU_Brightness[i]; i += 4; *bptr = (u8)pixels; pixels >>= 8; bptr += 2; *bptr = (u8)pixels; pixels >>= 8; bptr += 6; *bptr = (u8)pixels; pixels >>= 8; bptr += 2; *bptr = (u8)pixels; pixels >>= 8; bptr += 22; } // transfer the final color buffer to the LCD and clear it // we can mostly overlap those two operations GX_SetDisplayTransfer(gxCmdBuf, gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000); svcSleepThread(20000); GX_SetMemoryFill(gxCmdBuf, gpuOut, 0x404040FF, &gpuOut[0x2EE00], 0x201, gpuDOut, 0x00000000, &gpuDOut[0x2EE00], 0x201); gspWaitForPPF(); gspWaitForPSC0(); gspWaitForEvent(GSPEVENT_VBlank0, false); gfxSwapBuffersGpu(); } else if(status == APP_SUSPENDING)
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; const Uint8* keystates; GPU_Camera camera; float dt; SDL_Surface* surface; GPU_Image* image; GPU_Image* image1; GPU_Image* image2; GPU_Image* image3; GPU_Image* image4; image = GPU_LoadImage("data/test.bmp"); //image = GPU_LoadImage("data/big_test.png"); if(image == NULL) return -1; // Copying the annoying way image1 = GPU_CreateImage(image->w, image->h, GPU_FORMAT_RGBA); GPU_LoadTarget(image1); GPU_Blit(image, NULL, image1->target, image1->target->w/2, image1->target->h/2); GPU_FreeTarget(image1->target); // Copying the normal way image2 = GPU_CopyImage(image); // Copying from a surface dump surface = GPU_CopySurfaceFromImage(image); //GPU_SaveSurface(surface, "save_surf1.bmp", GPU_FILE_AUTO); image3 = GPU_CopyImageFromSurface(surface); SDL_FreeSurface(surface); // A buffer for window capture image4 = NULL; keystates = SDL_GetKeyState(NULL); camera = GPU_GetDefaultCamera(); startTime = SDL_GetTicks(); frameCount = 0; dt = 0.010f; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_SPACE) { // Take a window capture GPU_FreeImage(image4); image4 = GPU_CopyImageFromTarget(screen); } } } if(keystates[KEY_UP]) { camera.y -= 200*dt; } else if(keystates[KEY_DOWN]) { camera.y += 200*dt; } if(keystates[KEY_LEFT]) { camera.x -= 200*dt; } else if(keystates[KEY_RIGHT]) { camera.x += 200*dt; } if(keystates[KEY_MINUS]) { camera.zoom -= 1.0f*dt; } else if(keystates[KEY_EQUALS]) { camera.zoom += 1.0f*dt; } GPU_ClearRGBA(screen, 100, 100, 100, 255); GPU_SetCamera(screen, &camera); GPU_Blit(image, NULL, screen, 128, 128); GPU_Blit(image1, NULL, screen, 128 + 256, 128); GPU_Blit(image2, NULL, screen, 128 + 512, 128); GPU_Blit(image3, NULL, screen, 128, 128 + 256); if(image4 != NULL) GPU_BlitScale(image4, NULL, screen, 3*screen->w/4, 3*screen->h/4, 0.25f, 0.25f); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) GPU_LogError("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } GPU_LogError("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); GPU_FreeImage(image1); GPU_FreeImage(image2); GPU_FreeImage(image3); GPU_FreeImage(image4); } GPU_Quit(); return 0; }
//--------------------------------------------------------------------------- int main(int argc, char** argv) { touchPosition lastTouch; int frame=0,lp_frame=0; CWebRequest::InitializeClient(); gfxInitDefault(); GPU_Init(NULL); gfxSet3D(false); srand(svcGetSystemTick()); CFBClient::Initialize(); while(aptMainLoop()){ hidScanInput(); u32 press = hidKeysDown(); u32 held = hidKeysHeld(); u32 release = hidKeysUp(); if((press & ~KEY_TOUCH)){ CFBClient::onKeysPressEvent(press,1); hidCircleRead(&lcp); } if((release & ~KEY_TOUCH)){ CFBClient::onKeysUpEvent(press,1); hidCircleRead(&lcp); } if (held & KEY_TOUCH){ hidTouchRead(<); if(!lp_frame){ lastTouch=lt; lp_frame++; } else{ int i=0; if(abs(lt.px-lastTouch.px) <= 5){ if(abs(lt.py-lastTouch.py) <= 5) i = 1; } if(i) lp_frame++; else{ lp_frame = 0; CFBClient::onTouchEvent(<,2); } } if(!frame) CFBClient::onTouchEvent(<,1); frame++; } else{ if(frame) CFBClient::onTouchEvent(<,lp_frame > 120 ? 8 : 4); frame = 0; lp_frame = 0; } CFBClient::main(0); gfxFlushBuffers(); gfxSwapBuffers(); gspWaitForVBlank(); } CFBClient::Destroy(); CWebRequest::DestroyClient(); fsExit(); hidExit(); gfxExit(); aptExit(); srvExit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; int i = 0; float dt = 0.010f; #define MAX_GROUPS 30 Group groups[MAX_GROUPS]; int num_groups; memset(groups, 0, sizeof(Group)*MAX_GROUPS); num_groups = 0; groups[num_groups] = create_first_group(); num_groups++; startTime = SDL_GetTicks(); frameCount = 0; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) { for(i = 0; i < MAX_GROUPS; i++) { if(groups[i].target == NULL) { groups[i] = create_group(); num_groups++; GPU_Log("Added window %u. num_groups: %d\n", groups[i].target->context->windowID, num_groups); break; } } } else if(event.key.keysym.sym == SDLK_MINUS) { if(num_groups > 0) { for(i = MAX_GROUPS-1; i >= 0; i--) { if(groups[i].target != NULL) { GPU_Log("Removed window %u. num_groups: %d\n", groups[i].target->context->windowID, num_groups-1); destroy_group(groups, i); num_groups--; break; } } if(num_groups == 0) done = 1; } } } else if(event.type == SDL_MOUSEBUTTONDOWN) { GPU_Target* target = GPU_GetWindowTarget(event.button.windowID); if(target == NULL) GPU_Log("Clicked on window %u. NULL target.\n", event.button.windowID); else GPU_Log("Clicked on window %u. Target dims: %dx%d\n", event.button.windowID, target->w, target->h); } else if(event.type == SDL_WINDOWEVENT) { if(event.window.event == SDL_WINDOWEVENT_CLOSE) { Uint8 closed = 0; for(i = 0; i < MAX_GROUPS; i++) { if(groups[i].target != NULL && groups[i].target->context->windowID == event.window.windowID) { closed = 1; GPU_Log("Removed window %u. num_groups: %d\n", groups[i].target->context->windowID, num_groups-1); destroy_group(groups, i); num_groups--; break; } } // The last window was closed, then. if(!closed || num_groups == 0) done = 1; } } } for(i = 0; i < MAX_GROUPS; i++) { if(groups[i].target == NULL) continue; groups[i].sprite.x += groups[i].sprite.velx*dt; groups[i].sprite.y += groups[i].sprite.vely*dt; if(groups[i].sprite.x < 0) { groups[i].sprite.x = 0; groups[i].sprite.velx = -groups[i].sprite.velx; } else if(groups[i].sprite.x > screen_w) { groups[i].sprite.x = screen_w; groups[i].sprite.velx = -groups[i].sprite.velx; } if(groups[i].sprite.y < 0) { groups[i].sprite.y = 0; groups[i].sprite.vely = -groups[i].sprite.vely; } else if(groups[i].sprite.y > screen_h) { groups[i].sprite.y = screen_h; groups[i].sprite.vely = -groups[i].sprite.vely; } } for(i = 0; i < MAX_GROUPS; i++) { if(groups[i].target == NULL) continue; GPU_Clear(groups[i].target); GPU_Blit(groups[i].sprite.image, NULL, groups[i].target, groups[i].sprite.x, groups[i].sprite.y); GPU_Flip(groups[i].target); } frameCount++; if(frameCount%500 == 0) GPU_Log("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } GPU_Log("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); for(i = 0; i < MAX_GROUPS; i++) { if(groups[i].target == NULL) continue; destroy_group(groups, i); } } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; GPU_Image* image; GPU_Image* image1; GPU_Image* image1a; SDL_Color yellow = {246, 255, 0}; SDL_Color red = {200, 0, 0}; GPU_Image* image2; GPU_Image* image3; GPU_Image* image4; image = GPU_LoadImage("data/test3.png"); if(image == NULL) return -1; image1 = GPU_CopyImage(image); makeColorTransparent(image1, yellow); image1a = GPU_CopyImage(image); replaceColor(image1a, yellow, red); image2 = GPU_CopyImage(image); shiftHSV(image2, 100, 0, 0); image3 = GPU_CopyImage(image); shiftHSV(image3, 0, -100, 0); image4 = GPU_CopyImage(image); shiftHSV(image4, 0, 0, 100); startTime = SDL_GetTicks(); frameCount = 0; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } GPU_Clear(screen); GPU_Blit(image, NULL, screen, 150, 150); GPU_Blit(image1, NULL, screen, 300, 150); GPU_Blit(image1a, NULL, screen, 450, 150); GPU_Blit(image2, NULL, screen, 150, 300); GPU_Blit(image3, NULL, screen, 300, 300); GPU_Blit(image4, NULL, screen, 450, 300); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); GPU_FreeImage(image1); GPU_FreeImage(image1a); GPU_FreeImage(image2); GPU_FreeImage(image3); GPU_FreeImage(image4); } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { int numImages; GPU_Image** images; int i; const Uint8* keystates; GPU_Camera camera; float dt; Uint8 done; SDL_Event event; float x, y; images = (GPU_Image**)malloc(sizeof(GPU_Image*)*(argc - 1)); numImages = 0; for (i = 1; i < argc; i++) { images[numImages] = GPU_LoadImage(argv[i]); if (images[numImages] != NULL) numImages++; } keystates = SDL_GetKeyState(NULL); camera = GPU_GetDefaultCamera(); dt = 0.010f; done = 0; while (!done) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) done = 1; else if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if (event.key.keysym.sym == SDLK_r) { camera.x = 0.0f; camera.y = 0.0f; camera.z = -10.0f; camera.zoom = 1.0f; camera.angle = 0.0f; } } else if (event.type == SDL_MOUSEBUTTONDOWN) { float x, y; GPU_GetVirtualCoords(screen, &x, &y, event.button.x, event.button.y); printScreenToWorld(x, y); } } if (keystates[KEY_UP]) { camera.y -= 200 * dt; } else if (keystates[KEY_DOWN]) { camera.y += 200 * dt; } if (keystates[KEY_LEFT]) { camera.x -= 200 * dt; } else if (keystates[KEY_RIGHT]) { camera.x += 200 * dt; } if (keystates[KEY_MINUS]) { camera.zoom -= 1.0f*dt; } else if (keystates[KEY_EQUALS]) { camera.zoom += 1.0f*dt; } GPU_ClearRGBA(screen, 255, 255, 255, 255); GPU_SetCamera(screen, &camera); x = 0; y = 0; for (i = 0; i < numImages; i++) { x += images[i]->w / 2.0f; y += images[i]->h / 2.0f; GPU_Blit(images[i], NULL, screen, x, y); x += images[i]->w / 2.0f; y += images[i]->h / 2.0f; } GPU_Flip(screen); SDL_Delay(10); } for (i = 0; i < numImages; i++) { GPU_FreeImage(images[i]); } free(images); } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { printRenderers(); GPU_Target* screen = GPU_Init(1024, 700, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); GPU_Image* image = GPU_LoadImage("data/small_test.bmp"); if(image == NULL) return -1; SDL_Surface* font_surface = GPU_LoadSurface("data/comic14.png"); DemoFont* font = FONT_Alloc(font_surface); GPU_SetRGB(font->image, 255, 0, 0); SDL_FreeSurface(font_surface); GPU_Rect rect1 = {0.0f, 0.0f, image->w*3, image->h*3}; GPU_Rect rect2 = {-image->w*2, -image->h*2, image->w*3, image->h*3}; Uint32 startTime = SDL_GetTicks(); long frameCount = 0; Uint8 done = 0; SDL_Event event; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } GPU_Clear(screen); float x = 0; float y = 0; FONT_Draw(font, screen, x + 10, y + 10, "NONE"); x += 40; y += 20; GPU_SetWrapMode(image, GPU_WRAP_NONE, GPU_WRAP_NONE); GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2); x += image->w*4; GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2); x = 0; y += (rect1.h + 10); FONT_Draw(font, screen, x + 10, y + 10, "REPEAT"); x += 40; y += 20; GPU_SetWrapMode(image, GPU_WRAP_REPEAT, GPU_WRAP_REPEAT); GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2); x += image->w*4; GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2); x = 0; y += (rect1.h + 10); FONT_Draw(font, screen, x + 10, y + 10, "MIRRORED"); x += 40; y += 20; GPU_SetWrapMode(image, GPU_WRAP_MIRRORED, GPU_WRAP_MIRRORED); GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2); x += image->w*4; GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2); x = 500; y = 0; FONT_Draw(font, screen, x + 10, y + 10, "REPEAT/MIRRORED"); x += 40; y += 20; GPU_SetWrapMode(image, GPU_WRAP_REPEAT, GPU_WRAP_MIRRORED); GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2); x += image->w*4; GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2); x = 500; y += (rect1.h + 10); FONT_Draw(font, screen, x + 10, y + 10, "NONE/REPEAT"); x += 40; y += 20; GPU_SetWrapMode(image, GPU_WRAP_NONE, GPU_WRAP_REPEAT); GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2); x += image->w*4; GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2); x = 500; y += (rect1.h + 10); FONT_Draw(font, screen, x + 10, y + 10, "NONE/MIRRORED"); x += 40; y += 20; GPU_SetWrapMode(image, GPU_WRAP_NONE, GPU_WRAP_MIRRORED); GPU_Blit(image, &rect1, screen, x + rect1.w/2, y + rect1.h/2); x += image->w*4; GPU_Blit(image, &rect2, screen, x + rect2.w/2, y + rect2.h/2); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); FONT_Free(font); GPU_FreeImage(image); GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; int shapeType; int numShapeTypes; int i; #define NUM_COLORS 20 SDL_Color colors[NUM_COLORS]; #define NUM_PIXELS NUM_COLORS int px[NUM_PIXELS]; int py[NUM_PIXELS]; #define NUM_LINES NUM_COLORS int lx1[NUM_LINES]; int ly1[NUM_LINES]; int lx2[NUM_LINES]; int ly2[NUM_LINES]; #define NUM_TRIS NUM_COLORS int tx1[NUM_TRIS]; int ty1[NUM_TRIS]; int tx2[NUM_TRIS]; int ty2[NUM_TRIS]; int tx3[NUM_TRIS]; int ty3[NUM_TRIS]; #define NUM_RECTS NUM_COLORS int rx1[NUM_RECTS]; int ry1[NUM_RECTS]; int rx2[NUM_RECTS]; int ry2[NUM_RECTS]; float rr[NUM_RECTS]; #define NUM_ARCS NUM_COLORS int ax[NUM_ARCS]; int ay[NUM_ARCS]; float ar[NUM_ARCS]; float ar2[NUM_ARCS]; float aa1[NUM_ARCS]; float aa2[NUM_ARCS]; #define NUM_POLYS NUM_COLORS int pn[NUM_POLYS]; float* pv[NUM_POLYS]; Uint8 blend; float thickness; startTime = SDL_GetTicks(); frameCount = 0; shapeType = 0; numShapeTypes = 18; for(i = 0; i < NUM_COLORS; i++) { colors[i].r = rand()%256; colors[i].g = rand()%256; colors[i].b = rand()%256; GET_ALPHA(colors[i]) = rand()%256; } for(i = 0; i < NUM_PIXELS; i++) { px[i] = rand()%screen->w; py[i] = rand()%screen->h; } for(i = 0; i < NUM_LINES; i++) { lx1[i] = rand()%screen->w; ly1[i] = rand()%screen->h; lx2[i] = rand()%screen->w; ly2[i] = rand()%screen->h; } for(i = 0; i < NUM_TRIS; i++) { tx1[i] = rand()%screen->w; ty1[i] = rand()%screen->h; tx2[i] = rand()%screen->w; ty2[i] = rand()%screen->h; tx3[i] = rand()%screen->w; ty3[i] = rand()%screen->h; } for(i = 0; i < NUM_RECTS; i++) { rx1[i] = rand()%screen->w; ry1[i] = rand()%screen->h; rx2[i] = rand()%screen->w; ry2[i] = rand()%screen->h; rr[i] = rand()%10 + 2; } for(i = 0; i < NUM_ARCS; i++) { ax[i] = rand()%screen->w; ay[i] = rand()%screen->h; ar[i] = (rand()%screen->h)/10.0f; ar2[i] = ((rand()%101)/100.0f)*ar[i]; aa1[i] = rand()%360; aa2[i] = rand()%360; } for(i = 0; i < NUM_POLYS; i++) { float cx = rand()%screen->w; float cy = rand()%screen->h; float radius = 20 + rand()%(screen->w/8); int j; pn[i] = rand()%8 + 3; pv[i] = (float*)malloc(2*pn[i]*sizeof(float)); for(j = 0; j < pn[i]*2; j+=2) { pv[i][j] = cx + radius*cos(2*M_PI*(((float)j)/(pn[i]*2))) + rand()%((int)radius/2); pv[i][j+1] = cy + radius*sin(2*M_PI*(((float)j)/(pn[i]*2))) + rand()%((int)radius/2); } } blend = 0; thickness = 1.0f; GPU_SetShapeBlending(blend); done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_SPACE) { shapeType++; if(shapeType >= numShapeTypes) shapeType = 0; } else if(event.key.keysym.sym == SDLK_BACKSPACE) { shapeType--; if(shapeType < 0) shapeType = numShapeTypes-1; } else if(event.key.keysym.sym == SDLK_b) { blend = !blend; GPU_SetShapeBlending(blend); } else if(event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_EQUALS) { thickness += 0.25f; GPU_LogError("thickness: %.2f\n", thickness); GPU_SetLineThickness(thickness); } else if(event.key.keysym.sym == SDLK_DOWN || event.key.keysym.sym == SDLK_MINUS) { if(thickness > 0.25f) thickness -= 0.25f; GPU_LogError("thickness: %.2f\n", thickness); GPU_SetLineThickness(thickness); } } else if(event.type == SDL_MOUSEBUTTONDOWN) { if(event.button.button == SDL_BUTTON_LEFT) { shapeType++; if(shapeType >= numShapeTypes) shapeType = 0; } else if(event.button.button == SDL_BUTTON_RIGHT) { shapeType--; if(shapeType < 0) shapeType = numShapeTypes-1; } } } GPU_Clear(screen); switch(shapeType) { case 0: for(i = 0; i < NUM_PIXELS; i++) { GPU_Pixel(screen, px[i], py[i], colors[i]); } break; case 1: for(i = 0; i < NUM_LINES; i++) { GPU_Line(screen, lx1[i], ly1[i], lx2[i], ly2[i], colors[i]); } break; case 2: for(i = 0; i < NUM_TRIS; i++) { GPU_Tri(screen, tx1[i], ty1[i], tx2[i], ty2[i], tx3[i], ty3[i], colors[i]); } break; case 3: for(i = 0; i < NUM_TRIS; i++) { GPU_TriFilled(screen, tx1[i], ty1[i], tx2[i], ty2[i], tx3[i], ty3[i], colors[i]); } break; case 4: for(i = 0; i < NUM_RECTS; i++) { GPU_Rectangle(screen, rx1[i], ry1[i], rx2[i], ry2[i], colors[i]); } break; case 5: for(i = 0; i < NUM_RECTS; i++) { GPU_RectangleFilled(screen, rx1[i], ry1[i], rx2[i], ry2[i], colors[i]); } break; case 6: for(i = 0; i < NUM_RECTS; i++) { GPU_RectangleRound(screen, rx1[i], ry1[i], rx2[i], ry2[i], rr[i], colors[i]); } break; case 7: for(i = 0; i < NUM_RECTS; i++) { GPU_RectangleRoundFilled(screen, rx1[i], ry1[i], rx2[i], ry2[i], rr[i], colors[i]); } break; case 8: for(i = 0; i < NUM_ARCS; i++) { GPU_Arc(screen, ax[i], ay[i], ar[i], aa1[i], aa2[i], colors[i]); } break; case 9: for(i = 0; i < NUM_ARCS; i++) { GPU_ArcFilled(screen, ax[i], ay[i], ar[i], aa1[i], aa2[i], colors[i]); } break; case 10: for(i = 0; i < NUM_ARCS; i++) { GPU_Circle(screen, ax[i], ay[i], ar[i], colors[i]); } break; case 11: for(i = 0; i < NUM_ARCS; i++) { GPU_CircleFilled(screen, ax[i], ay[i], ar[i], colors[i]); } break; case 12: for(i = 0; i < NUM_ARCS; i++) { GPU_Ellipse(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], colors[i]); } break; case 13: for(i = 0; i < NUM_ARCS; i++) { GPU_EllipseFilled(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], colors[i]); } break; case 14: for(i = 0; i < NUM_ARCS; i++) { GPU_Sector(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], aa2[i], colors[i]); } break; case 15: for(i = 0; i < NUM_ARCS; i++) { GPU_SectorFilled(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], aa2[i], colors[i]); } break; case 16: for(i = 0; i < NUM_POLYS; i++) { GPU_Polygon(screen, pn[i], pv[i], colors[i]); } break; case 17: for(i = 0; i < NUM_POLYS; i++) { GPU_PolygonFilled(screen, pn[i], pv[i], colors[i]); } break; } GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); for(i = 0; i < NUM_POLYS; i++) { free(pv[i]); } } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); GPU_SetPreInitFlags(GPU_INIT_DISABLE_VSYNC); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; float dt = 0.010f; int maxSprites = 50000; int numSprites = 101; float* x = (float*)malloc(sizeof(float)*maxSprites); float* y = (float*)malloc(sizeof(float)*maxSprites); float* velx = (float*)malloc(sizeof(float)*maxSprites); float* vely = (float*)malloc(sizeof(float)*maxSprites); int i; GPU_Image* image = GPU_LoadImage("data/small_test.png"); if(image == NULL) return -1; GPU_SetSnapMode(image, GPU_SNAP_NONE); startTime = SDL_GetTicks(); frameCount = 0; for(i = 0; i < maxSprites; i++) { x[i] = rand()%screen->w; y[i] = rand()%screen->h; velx[i] = 10 + rand()%screen->w/10; vely[i] = 10 + rand()%screen->h/10; if(rand()%2) velx[i] = -velx[i]; if(rand()%2) vely[i] = -vely[i]; } done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) { if(numSprites < maxSprites) numSprites += 100; GPU_LogError("Sprites: %d\n", numSprites); frameCount = 0; startTime = SDL_GetTicks(); } else if(event.key.keysym.sym == SDLK_MINUS) { if(numSprites > 1) numSprites -= 100; if(numSprites < 1) numSprites = 1; GPU_LogError("Sprites: %d\n", numSprites); frameCount = 0; startTime = SDL_GetTicks(); } } } for(i = 0; i < numSprites; i++) { x[i] += velx[i]*dt; y[i] += vely[i]*dt; if(x[i] < 0) { x[i] = 0; velx[i] = -velx[i]; } else if(x[i]> screen->w) { x[i] = screen->w; velx[i] = -velx[i]; } if(y[i] < 0) { y[i] = 0; vely[i] = -vely[i]; } else if(y[i]> screen->h) { y[i] = screen->h; vely[i] = -vely[i]; } } GPU_Clear(screen); for(i = 0; i < numSprites; i++) { GPU_Blit(image, NULL, screen, x[i], y[i]); } GPU_Flip(screen); frameCount++; if(SDL_GetTicks() - startTime > 5000) { printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); frameCount = 0; startTime = SDL_GetTicks(); } } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); free(x); free(y); free(velx); free(vely); GPU_FreeImage(image); } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; GPU_Image* image; Uint32 v, f, p; GPU_ShaderBlock block; int uloc; int timeloc; float dt; #define MAX_SPRITES 50 int numSprites; float x[MAX_SPRITES]; float y[MAX_SPRITES]; float velx[MAX_SPRITES]; float vely[MAX_SPRITES]; int i; image = GPU_LoadImage("data/test.bmp"); if(image == NULL) return -1; block = load_shaders(&v, &f, &p); uloc = GPU_GetUniformLocation(p, "tex"); GPU_SetUniformi(uloc, 0); timeloc = GPU_GetUniformLocation(p, "time"); dt = 0.010f; startTime = SDL_GetTicks(); frameCount = 0; numSprites = 1; for(i = 0; i < MAX_SPRITES; i++) { x[i] = rand()%screen->w; y[i] = rand()%screen->h; velx[i] = 10 + rand()%screen->w/10; vely[i] = 10 + rand()%screen->h/10; } done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) { if(numSprites < MAX_SPRITES) numSprites++; } else if(event.key.keysym.sym == SDLK_MINUS) { if(numSprites > 0) numSprites--; } else if(event.key.keysym.sym == SDLK_SPACE) { if(GPU_IsDefaultShaderProgram(GPU_GetCurrentShaderProgram())) { GPU_ActivateShaderProgram(p, &block); uloc = GPU_GetUniformLocation(p, "tex"); GPU_SetUniformi(uloc, 0); timeloc = GPU_GetUniformLocation(p, "time"); } else GPU_ActivateShaderProgram(0, NULL); } } } for(i = 0; i < numSprites; i++) { x[i] += velx[i]*dt; y[i] += vely[i]*dt; if(x[i] < 0) { x[i] = 0; velx[i] = -velx[i]; } else if(x[i]> screen->w) { x[i] = screen->w; velx[i] = -velx[i]; } if(y[i] < 0) { y[i] = 0; vely[i] = -vely[i]; } else if(y[i]> screen->h) { y[i] = screen->h; vely[i] = -vely[i]; } } GPU_SetUniformf(timeloc, SDL_GetTicks()/1000.0f); GPU_Clear(screen); for(i = 0; i < numSprites; i++) { GPU_Blit(image, NULL, screen, x[i], y[i]); } GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); free_shaders(v, f, p); } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; GPU_Image* image; #define MAX_SPRITES 100 int numSprites; float positions[2*MAX_SPRITES]; float colors[4*4*MAX_SPRITES]; float expanded_colors[4*MAX_SPRITES]; float src_rects[4*MAX_SPRITES]; Uint32 v, f, p; GPU_ShaderBlock block; Uint8 shader_index; int i; SDL_Color color = {255, 255, 255, 255}; SDL_Color red = {255, 0, 0, 255}; SDL_Color green = {0, 255, 0, 255}; SDL_Color blue = {0, 0, 255, 255}; GPU_Rect src_rect; int mx, my; Uint32 mouse_state; image = GPU_LoadImage("data/happy_50x50.bmp"); if(image == NULL) return -1; numSprites = 0; color_attr.format = GPU_MakeAttributeFormat(4, GPU_TYPE_FLOAT, 0, 4*sizeof(float), 0); color_attr.format.is_per_sprite = 0; color_attr.values = colors; block = load_shaders(&v, &f, &p); shader_index = 1; set_shader(p, &block); startTime = SDL_GetTicks(); frameCount = 0; src_rect.x = 0; src_rect.y = 0; src_rect.w = image->w; src_rect.h = image->h; add_sprite(positions, colors, expanded_colors, src_rects, &numSprites, color, src_rect); done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_MOUSEBUTTONDOWN) { if(event.button.x <= 150 && event.button.y <= 150) { if(event.button.button == SDL_BUTTON_LEFT) { float dx = event.button.x/3 - src_rect.x; float dy = event.button.y/3 - src_rect.y; src_rect.x = event.button.x/3; src_rect.y = event.button.y/3; src_rect.w -= dx; src_rect.h -= dy; } else if(event.button.button == SDL_BUTTON_RIGHT) { src_rect.w = event.button.x/3 - src_rect.x; src_rect.h = event.button.y/3 - src_rect.y; } } } else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) { if(numSprites < MAX_SPRITES) add_sprite(positions, colors, expanded_colors, src_rects, &numSprites, color, src_rect); } else if(event.key.keysym.sym == SDLK_MINUS) { if(numSprites > 0) numSprites--; } else if(event.key.keysym.sym == SDLK_SPACE) { shader_index++; shader_index %= 2; if(shader_index == 0) set_shader(0, NULL); else if(shader_index == 1) set_shader(p, &block); } else if(event.key.keysym.sym == SDLK_RETURN) { use_color_expansion = !use_color_expansion; if(use_color_expansion) { GPU_LogError("Using attribute expansion.\n"); color_attr.format.is_per_sprite = 1; color_attr.values = expanded_colors; } else { GPU_LogError("Using per-vertex attributes.\n"); color_attr.format.is_per_sprite = 0; color_attr.values = colors; } } } } mouse_state = SDL_GetMouseState(&mx, &my); if(mouse_state & (SDL_BUTTON_LMASK | SDL_BUTTON_RMASK)) { if(mx <= 150 && my <= 150) { if(mouse_state & SDL_BUTTON_LMASK) { float dx = mx/3 - src_rect.x; float dy = my/3 - src_rect.y; src_rect.x = mx/3; src_rect.y = my/3; src_rect.w -= dx; src_rect.h -= dy; } else if(mouse_state & SDL_BUTTON_RMASK) { src_rect.w = mx/3 - src_rect.x; src_rect.h = my/3 - src_rect.y; } } } GPU_SetUniformf(timeloc, SDL_GetTicks()/1000.0f); GPU_Clear(screen); if(use_color_expansion) GPU_SetAttributeSource(numSprites, color_attr); else GPU_SetAttributeSource(4*numSprites, color_attr); for(i = 0; i < numSprites; i++) { GPU_Rect r = {src_rects[4*i], src_rects[4*i+1], src_rects[4*i+2], src_rects[4*i+3]}; GPU_Blit(image, &r, screen, positions[2*i], positions[2*i+1]); } //GPU_BlitBatchSeparate(image, screen, numSprites, positions, src_rects, expanded_colors, 0); set_shader(0, NULL); GPU_BlitScale(image, NULL, screen, 75, 75, 3.0f, 3.0f); GPU_Rectangle(screen, 3*src_rect.x, 3*src_rect.y, 3*(src_rect.x + src_rect.w), 3*(src_rect.y + src_rect.h), red); GPU_CircleFilled(screen, 3*src_rect.x, 3*src_rect.y, 4, blue); GPU_CircleFilled(screen, 3*(src_rect.x + src_rect.w), 3*(src_rect.y + src_rect.h), 4, green); if(shader_index == 1) set_shader(p, &block); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); free_shaders(v, f, p); } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) return -1; printCurrentRenderer(); { GPU_Image* image; GPU_Target* alias_target; GPU_Image* alias_image; Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; image = GPU_LoadImage("data/test.bmp"); if (image == NULL) return -1; alias_target = GPU_CreateAliasTarget(screen); GPU_SetViewport(screen, GPU_MakeRect(50, 30, 400, 300)); GPU_SetViewport(alias_target, GPU_MakeRect(400, 30, 400, 300)); GPU_SetTargetRGBA(alias_target, 255, 100, 100, 200); alias_image = GPU_CreateAliasImage(image); GPU_SetImageFilter(alias_image, GPU_FILTER_NEAREST); GPU_SetRGBA(alias_image, 100, 255, 100, 200); startTime = SDL_GetTicks(); frameCount = 0; done = 0; while (!done) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) done = 1; else if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } GPU_Clear(screen); GPU_Blit(image, NULL, screen, image->w / 2, image->h / 2); GPU_Blit(alias_image, NULL, screen, image->w + alias_image->w / 2, alias_image->h / 2); GPU_Blit(image, NULL, alias_target, image->w / 2, image->h / 2); GPU_Blit(alias_image, NULL, alias_target, image->w + alias_image->w / 2, alias_image->h / 2); GPU_Flip(screen); frameCount++; if (frameCount % 500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount / (SDL_GetTicks() - startTime)); GPU_FreeImage(alias_image); GPU_FreeImage(image); GPU_FreeTarget(alias_target); } GPU_Quit(); return 0; }
int main(int argc, char* argv[]) { GPU_Target* screen; printRenderers(); screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS); if(screen == NULL) { GPU_LogError("Failed to init SDL_gpu.\n"); return -1; } printCurrentRenderer(); { Uint32 startTime; long frameCount; Uint8 done; SDL_Event event; GPU_Image* image; GPU_Image* image1; GPU_LogError("Loading image\n"); image = GPU_LoadImage(IMAGE_FILE); if(image == NULL) { GPU_LogError("Failed to load image.\n"); return -1; } GPU_LogError("Saving image\n"); GPU_SaveImage(image, SAVE_FILE, GPU_FILE_AUTO); GPU_LogError("Reloading image\n"); image1 = GPU_LoadImage(SAVE_FILE); if(image1 == NULL) { GPU_LogError("Failed to reload image.\n"); return -1; } startTime = SDL_GetTicks(); frameCount = 0; done = 0; while(!done) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) done = 1; else if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } } GPU_Clear(screen); GPU_Blit(image, NULL, screen, screen->w/4, screen->h/2); GPU_Blit(image1, NULL, screen, 3*screen->w/4, screen->h/2); GPU_Flip(screen); frameCount++; if(frameCount%500 == 0) printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); } printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); GPU_FreeImage(image); GPU_FreeImage(image1); } GPU_Quit(); return 0; }