void desenha_textura(char imageTela[30]) { glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D); printTexture(imageTela); glutSwapBuffers(); }
int main() { GPGPU::EnginePtr engine = GPGPU::create(); try { engine->initialise(); } catch(GPGPU::Exception &e) { std::cerr << e.getDescription() << std::endl; return 1; } try { std::cerr << "Initialising the pool" << std::endl; GPGPU::TexturePool pool; pool.setCapacity(5); /// Create template GPGPU::TexturePtr temp = engine->createTexture(); const size_t cellsx = 32; const size_t cellsy = 32; const size_t cellsz = 32; const size_t logwidth = 4; const size_t logheight = 4; const size_t height = 1<<logwidth; const size_t width = 1<<logheight; const float cellsizex = 4; const float cellsizey = 4; const float cellsizez = 4; temp->setSize(height, width); temp->setInternalFormat(GPGPU::PC_RGBA, GPGPU::PT_FLOAT32); temp->setRenderTarget(true); pool.setTemplate(temp); pool.initialise(); /// Load a program std::string programText = loadText("shaders/Particle.cg"); if(programText.empty()) { std::cerr << "Particle.cg could not be loaded" << std::endl; return 1; } GPGPU::ProgramPtr posToCell = engine->createProgram("Cg"); posToCell->setSource(programText); posToCell->setEntryPoint("posToCell"); posToCell->initialise(); GPGPU::ProgramPtr initial = engine->createProgram("Cg"); initial->setSource(programText); initial->setEntryPoint("initial"); initial->initialise(); GPGPU::ProgramPtr searchV = engine->createProgram("Cg"); searchV->setSource(programText); searchV->setEntryPoint("searchVertical"); searchV->initialise(); GPGPU::ProgramPtr initH = engine->createProgram("Cg"); initH->setSource(programText); initH->setEntryPoint("initialHorizontal"); initH->initialise(); GPGPU::ProgramPtr searchH = engine->createProgram("Cg"); searchH->setSource(programText); searchH->setEntryPoint("searchHorizontal"); searchH->initialise(); GPGPU::ProgramPtr testLookup = engine->createProgram("Cg"); testLookup->setSource(programText); testLookup->setEntryPoint("testLookup"); testLookup->initialise(); /// Create sorting network DowdSortingNetwork *sorter = new DowdSortingNetwork(); sorter->setSize(width, height); sorter->setPrecision("Float"); sorter->initialize(); /// Get a texture GPGPU::TextureLease positions; /// Here are the values to look up positions = pool.getLease(); fillTestData(positions.get()); std::cerr << "Positions are: " << std::endl; printTexture(positions.get(), 0); std::cerr << std::endl; printTexture(positions.get(), 1); std::cerr << std::endl; printTexture(positions.get(), 2); std::cerr << "Cell IDS (search space) are: " << std::endl; /// Positions to cellids GPGPU::TextureLease cellids = pool.getLease(); engine->setProgram(posToCell); posToCell->setParameter("positions", positions.get()); posToCell->setParameter("stagger", 0,0,0); posToCell->setParameter("cellmult", 1,cellsx,cellsx*cellsy); posToCell->setParameter("cellsize", cellsizex,cellsizey,cellsizez); engine->setTarget(cellids.get()); engine->quadBlit(); /// Define search space by sorting cellids GPGPU::TextureLease searchspace = cellids; sorter->sort(&pool, searchspace); engine->setTarget(); printTexture(searchspace.get(), 0); /// Create another texture (needle) GPGPU::TextureLease x; x = pool.getLease(); /// Working texture initial->setParameter("height", height); initial->setParameter("cellids", cellids.get()); engine->setTarget(x.get()); engine->setProgram(initial); engine->quadBlit(); engine->setTarget(); std::cerr << "Needle space is: " << std::endl; printTexture(x.get(), 2); /// Run the loop Timer t; t.start(); // Sort vertical engine->setProgram(searchV); searchV->setParameter("haystack", searchspace.get()); for(size_t i=0; i<logwidth; i++) { GPGPU::TextureLease y = pool.getLease(); searchV->setParameter("needle", x.get()); engine->setTarget(y.get()); engine->quadBlit(); x = y; } // Initialize horizontal sorting { GPGPU::TextureLease y = pool.getLease(); engine->setProgram(initH); initH->setParameter("width", width); initH->setParameter("needle", x.get()); engine->setTarget(y.get()); engine->quadBlit(); x = y; } // Sort horizontal engine->setProgram(searchH); searchH->setParameter("haystack", searchspace.get()); for(size_t i=0; i<logheight; i++) { GPGPU::TextureLease y = pool.getLease(); searchH->setParameter("needle", x.get()); engine->setTarget(y.get()); engine->quadBlit(); x = y; } engine->setTarget(); dummyLoadTexture(x.get()); t.stop(); std::cerr << "Time elapsed: " << t.getSeconds() << std::endl; // x.get now has x components in [0] and y components in [3] of lastmost particle in this cell // all other particles in this cell well appear before this position printTextureWX(x.get()); // Test lookup { GPGPU::TextureLease y = pool.getLease(); engine->setProgram(testLookup); testLookup->setParameter("width", width); testLookup->setParameter("haystack", searchspace.get()); testLookup->setParameter("needle", x.get()); testLookup->setParameter("positions", positions.get()); engine->setTarget(y.get()); engine->quadBlit(); engine->setTarget(); printTexture(y.get(), 0); } } catch(GPGPU::Exception &e) { std::cerr << e.getDescription() << std::endl; } return 0; }
int main() { GPGPU::EnginePtr engine = GPGPU::create(); try { engine->initialise(); } catch(GPGPU::Exception &e) { std::cerr << e.getDescription() << std::endl; return 1; } try { std::cerr << "Initialising the pool" << std::endl; GPGPU::TexturePool pool; pool.setCapacity(3); /// Create template GPGPU::TexturePtr temp = engine->createTexture(); temp->setSize(16,16); //temp->setType(GL_TEXTURE_2D); //temp->setWrapping(GL_REPEAT, GL_REPEAT, GL_REPEAT); // PT_FLOAT16 broken on ati temp->setInternalFormat(GPGPU::PC_RGBA, GPGPU::PT_FLOAT32); temp->setRenderTarget(true); pool.setTemplate(temp); pool.initialise(); /// Load a program std::string programText = loadText("shaders/Test.cg"); if(programText.empty()) { std::cerr << "Test.cg could not be loaded" << std::endl; return 1; } GPGPU::ProgramPtr diffuse = engine->createProgram("Cg"); diffuse->setSource(programText); diffuse->setEntryPoint("coord"); diffuse->initialise(); /// Get a texture GPGPU::TextureLease x; x = pool.getLease(); /// Load data into texture /*float data[256]; for(size_t x=0; x<256; x++) data[x] = 0.0f; data[8*16+8] = 1.0f; x->loadData(GPGPU::PC_R, GPGPU::PT_FLOAT32, data); */ GPGPU::VertexStreamPtr stream = engine->createVertexStream(); stream->setVertexCount(8*8*4); stream->declareVertexAttribute(2, GPGPU::AS_POSITION); stream->declareVertexAttribute(2, GPGPU::AS_TEXCOORD0); stream->initialise(); float *str = stream->lock(); /* for(size_t y=0; y<2; y++) for(size_t x=0; x<2; x++) { GPGPU::emitFloats(str, x*8+8, y*8+0, 8, 0); // Right top GPGPU::emitFloats(str, x*8+0, y*8+0, 0, 0); // Left top GPGPU::emitFloats(str, x*8+0, y*8+8, 0, 8); // Left bottom GPGPU::emitFloats(str, x*8+8, y*8+8, 8, 8); // Right bottom } */ for(size_t y=0; y<8; y++) for(size_t x=0; x<8; x++) { GPGPU::emitFloats(str, x*2+2, y*2+0, x*2+2, y*2+0); // Right top GPGPU::emitFloats(str, x*2+0, y*2+0, x*2+0, y*2+0); // Left top GPGPU::emitFloats(str, x*2+0, y*2+2, x*2+0, y*2+2); // Left bottom GPGPU::emitFloats(str, x*2+2, y*2+2, x*2+2, y*2+2); // Right bottom } stream->unlock(); /// Run the loop Timer t; t.start(); for(size_t i=0; i<1; i++) { GPGPU::TextureLease y = pool.getLease(); engine->setTarget(y.get()); //diffuse->setParameter("input", x.get()); engine->setProgram(diffuse); engine->executeVertexStream(stream); //engine->quadBlit(); x = y; } engine->setTarget(); dummyLoadTexture(x.get()); t.stop(); std::cerr << "Time elapsed: " << t.getSeconds() << std::endl; printTexture(x.get()); } catch(GPGPU::Exception &e) { std::cerr << e.getDescription() << std::endl; } return 0; }
void Desenha() { char imageTela[30]="./texturas/abertura3.bmp"; DESENHA_TEXTO(330,180,imageTela); if(ENTER==0) { desenha_textura(imageTela); } switch(ENTER) { case 1: glDisable(GL_TEXTURE_2D); glClear(GL_COLOR_BUFFER_BIT); char str1[7]= "JOGAR"; char str2[7]= "AJUDA"; char str3[7]= "SOBRE"; char str4[6]= "SAIR"; char str5[7]= "SCORE"; char str6[7]= "VIDAS"; char nomeimag[]="./texturas/Menu.bmp"; glColor3f(1,1,1); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D); printTexture(nomeimag); glLoadIdentity(); glColor3f(0,0,1); DESENHA_TEXTO(130,90,str1); DESENHA_TEXTO(130,75,str2); DESENHA_TEXTO(130,60,str3); DESENHA_TEXTO(130,45,str4); if(esc == 0) { glColor3f(1.0f,0.0f,0.0f); ghost_abertura(0); glColor3f(0.0f,1.0f,1.0f); ghost_abertura(15); glColor3f(1.0f,0.6f,0.0f); ghost_abertura(30); glColor3f(1.0f,0.0f,1.0f); ghost_abertura(45); } else { glColor3f(0.0f,0.0f,1.0f); ghost_abertura(0); glColor3f(0.0f,0.0f,1.0f); ghost_abertura(15); glColor3f(0.0f,0.0f,1.0f); ghost_abertura(30); glColor3f(0.0f,0.0f,1.0f); ghost_abertura(45); } Bola_Pacman(215,101); Desenha_Pacman_abertura(); glColor3f(1.0f,1.0f,0.0f); Desenha_esc_menu(); Colisao(); switch(esc_menu) { case 1: glColor3f(1,1,1); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_TEXTURE_2D); Labirinto(); glColor3f(1.0f,0.0f,0.0f); ghost_BLINKY(0,0); glColor3f(0.0f,1.0f,1.0f); ghost_INKY(18,-30); glColor3f(1.0f,0.0f,1.0f); ghost_PINKY(0,-30); glColor3f(1.0f,0.6f,0.0f); ghost_CLYDE(-18,-30); Desenha_Pacman(); glutPostRedisplay(); Desenha_life(VIVO,VIVO); glColor3f(1,1,1); DESENHA_TEXTO(360,180,str5); DESENHA_TEXTO(360,150,str6); break; case 2: Desenha_ajuda(); break; case 3: Desenha_sobre(); break; case 4: exit(0); break; } glutSwapBuffers(); break; } }