// Returns a prepared Texture* that either is already in the cache or can fit // in the cache (and is thus added to the cache) Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) { if (CC_LIKELY(mAssetAtlas != nullptr) && atlasUsageType == AtlasUsageType::Use) { AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap); if (CC_UNLIKELY(entry)) { return entry->texture; } } Texture* texture = mCache.get(bitmap->pixelRef()->getStableID()); if (!texture) { if (!canMakeTextureFromBitmap(bitmap)) { return nullptr; } const uint32_t size = bitmap->rowBytes() * bitmap->height(); bool canCache = size < mMaxSize; // Don't even try to cache a bitmap that's bigger than the cache while (canCache && mSize + size > mMaxSize) { Texture* oldest = mCache.peekOldestValue(); if (oldest && !oldest->isInUse) { mCache.removeOldest(); } else { canCache = false; } } if (canCache) { texture = new Texture(Caches::getInstance()); texture->bitmapSize = size; generateTexture(bitmap, texture, false); mSize += size; TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d", bitmap, texture->id, size, mSize); if (mDebugEnabled) { ALOGD("Texture created, size = %d", size); } mCache.put(bitmap->pixelRef()->getStableID(), texture); } } else if (!texture->isInUse && bitmap->getGenerationID() != texture->generation) { // Texture was in the cache but is dirty, re-upload // TODO: Re-adjust the cache size if the bitmap's dimensions have changed generateTexture(bitmap, texture, true); } return texture; }
void Texture::setFileName(QString fileName) { if (this->fileName != fileName) { this->fileName = fileName; } generateTexture(); }
VolumeGL::VolumeGL(const Volume* volume) throw (VoreenException, std::bad_alloc) : VolumeRepresentation(volume->getDimensions()) , texture_(0) { tgtAssert(volume, "No volume"); generateTexture(volume); }
VolumeGL::VolumeGL(const VolumeRAM* volume) throw (tgt::Exception, std::bad_alloc) : VolumeRepresentation(volume->getDimensions()) , texture_(0) { assert(volume); generateTexture(volume); }
bool Texture::Load(const char *filename) { // hook for generated textures if (!memcmp(filename, "gen:", 4)) { // TODO // return false; tex_ = (LPVOID)generateTexture(filename); if (tex_) { this->filename_ = filename; } return true; } filename_ = filename; // Currently contains many Rollerball-specific workarounds. // They shouldn't really hurt anything else very much though. int len = strlen(filename); char fn[256]; strcpy(fn, filename); bool zim = false; if (!strcmp("dds", &filename[len-3])) { strcpy(&fn[len-3], "zim"); zim = true; } if (!strcmp("6TX", &filename[len-3]) || !strcmp("6tx", &filename[len-3])) { ILOG("Detected 6TX %s", filename); strcpy(&fn[len-3], "zim"); zim = true; } for (int i = 0; i < (int)strlen(fn); i++) { if (fn[i] == '\\') fn[i] = '/'; } if (fn[0] == 'm') fn[0] = 'M'; const char *name = fn; if (zim && 0 == memcmp(name, "Media/textures/", strlen("Media/textures"))) name += strlen("Media/textures/"); len = strlen(name); #if !defined(USING_GLES2) if (!strcmp("png", &name[len-3]) || !strcmp("PNG", &name[len-3])) { if (!LoadPNG(fn)) { LoadXOR(); return false; } else { return true; } } else #endif if (!strcmp("zim", &name[len-3])) { if (!LoadZIM(name)) { LoadXOR(); return false; } else { return true; } } LoadXOR(); return false; }
void ofxDepthGenerator::update() { // get meta-data depth_generator.GetMetaData(dmd); generateTexture(); if (max_number_depths > 1) { updateMaskPixels(); } }
Texture* TextureCache::getTransient(SkBitmap* bitmap) { Texture* texture = new Texture; texture->bitmapSize = bitmap->rowBytes() * bitmap->height(); texture->cleanup = true; generateTexture(bitmap, texture, false); return texture; }
Renderer::Renderer(BaseEntity *entity, std::string texturePath) { this->parentEntity = entity; _id = total + 1; generateTexture(texturePath); RenderHandler::registerRenderer(this); }
void Range::draw(SDL_Renderer * renderer) { if(isVisible()) { if(needReDraw) { generateTexture(renderer); needReDraw = false; } SDL_RenderCopy(renderer,texture,nullptr,&area); } }
Texture* TextureCache::get(SkBitmap* bitmap) { Texture* texture = mCache.get(bitmap); if (!texture) { if (bitmap->width() > mMaxTextureSize || bitmap->height() > mMaxTextureSize) { ALOGW("Bitmap too large to be uploaded into a texture (%dx%d, max=%dx%d)", bitmap->width(), bitmap->height(), mMaxTextureSize, mMaxTextureSize); return NULL; } const uint32_t size = bitmap->rowBytes() * bitmap->height(); // Don't even try to cache a bitmap that's bigger than the cache if (size < mMaxSize) { while (mSize + size > mMaxSize) { mCache.removeOldest(); } } texture = new Texture; texture->bitmapSize = size; generateTexture(bitmap, texture, false); if (size < mMaxSize) { mSize += size; TEXTURE_LOGD("TextureCache::get: create texture(%p): name, size, mSize = %d, %d, %d", bitmap, texture->id, size, mSize); if (mDebugEnabled) { ALOGD("Texture created, size = %d", size); } mCache.put(bitmap, texture); } else { texture->cleanup = true; } } else if (bitmap->getGenerationID() != texture->generation) { generateTexture(bitmap, texture, true); } return texture; }
void Entity::initialize() { QByteArray vsrc = "attribute highp vec4 vertexAttr;\n" "attribute highp vec2 texAttr;\n" "uniform mediump mat4 matrix;\n" "varying highp vec2 texCoord;\n" "void main(void)\n" "{\n" " texCoord = texAttr;\n" " gl_Position = matrix * vertexAttr;\n" "}\n"; QByteArray fsrc = "uniform sampler2D texture;\n" "varying highp vec2 texCoord;\n" "void main(void)\n" "{\n" " gl_FragColor = texture2D(texture, texCoord);\n" "}\n"; m_program = generateShaderProgram(this, vsrc, fsrc); m_vertexAttr = m_program->attributeLocation("vertexAttr"); m_texAttr = m_program->attributeLocation("texAttr"); m_matrixUniform = m_program->uniformLocation("matrix"); QVector<QImage> images = loadSoldierImages(); int w = images.first().width() + 2; int h = images.first().height() + 2; m_tileMod = (images.size() + 3) / 4; QImage image(m_tileMod * w, 4 * h, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter p(&image); p.setCompositionMode(QPainter::CompositionMode_Source); for (int i = 0; i < images.size(); ++i) p.drawImage(w * (i % m_tileMod) + 1, h * (i / m_tileMod) + 1, images.at(i)); p.end(); qDebug() << "Initialized soldier image" << image.size(); m_tileWidth = w; m_tileHeight = h; m_texture = generateTexture(image, false, false); m_textureSize = image.size(); }
//---------------------------------------------- void myDepthGenerator::update(soDepthThresholds thresholds) { if (depth_generator.IsNewDataAvailable()) { depth_generator.WaitAndUpdateData(); depth_generator.GetMetaData(dmd); privThresholds = thresholds; generateTexture(); generateMonoTexture(); } }
CTexture* CPlanetTextureGenerator::generatePlanetTexture(const int planetTexWidth, const int planetTexHeight, const PlanetGenerationParams* params, const int bpp) { float eps = 0.00001f; currPlanetParams = params; hasCloudTexture = true; hasLumTexture = true; hasLiquidTexture = true; if (currPlanetParams->cloudPart < eps) hasCloudTexture = false; if (currPlanetParams->lumPart < eps) hasLumTexture = false; if (currPlanetParams->liquidPart < eps) hasLiquidTexture = false; return generateTexture(planetTexWidth, planetTexHeight, bpp); }
Texture* TextureCache::get(const SkBitmap* bitmap) { Texture* texture = getCachedTexture(bitmap); if (!texture) { if (!canMakeTextureFromBitmap(bitmap)) { return NULL; } const uint32_t size = bitmap->rowBytes() * bitmap->height(); texture = new Texture(); texture->bitmapSize = size; generateTexture(bitmap, texture, false); texture->cleanup = true; } return texture; }
Texture* TextureCache::get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) { Texture* texture = getCachedTexture(bitmap, atlasUsageType); if (!texture) { if (!canMakeTextureFromBitmap(bitmap)) { return nullptr; } const uint32_t size = bitmap->rowBytes() * bitmap->height(); texture = new Texture(Caches::getInstance()); texture->bitmapSize = size; generateTexture(bitmap, texture, false); texture->cleanup = true; } return texture; }
//---------------------------------------------- bool myDepthGenerator::update(){ if (!bUpdateXtion[thisNum]) return; bool isNewDataAvailable = false; if (depth_generator.IsNewDataAvailable()) { depth_generator.WaitAndUpdateData(); depth_generator.GetMetaData(dmd); generateCurrentDepth(); generateTexture(); generateRealWorld(realWorld); isNewDataAvailable = true; } checkSwitchMethods(); counter++; return isNewDataAvailable; }
void projector::setup() { Renderer.init(); Renderer.addShader(GL_VERTEX_SHADER, AssetManager::GetAppPath() + "../../code/shader/projector.vert"); if (projtype == IMAGE) { Renderer.addShader(GL_FRAGMENT_SHADER, AssetManager::GetAppPath() + "../../code/shader/projector.frag"); } else { Renderer.addShader(GL_FRAGMENT_SHADER, AssetManager::GetAppPath() + "../../code/shader/projector2.frag"); } cout << Renderer.compile() << endl; cout << Renderer.link() << endl; float verts[12] = { -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0 }; Buffer.generateBuffer(GL_ARRAY_BUFFER); Buffer.bindBuffer(); Buffer.allocateBufferData(sizeof(verts), &verts[0], GL_STATIC_DRAW); cout << "FILENAME: " << filename << endl; double x, y; string projection; if (projtype == IMAGE) { generateImageTexture(filename, tex, projection, x, y, width, height, xres, yres); } else { generateTexture(filename, tex, bandnum,projection, x, y, width, height, xres, yres); } origin.x = x; origin.y = y; // Lets construct the projection char* test = &projection[0]; sr.importFromWkt(&test); SetDimensions(width * xres, height * yres); }
int main(void) { static constexpr int screnWidth = 800; static constexpr int screnHeight = 600; int textureWidth = 0, textureHeight = 0, channel = 0; GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); window = glfwCreateWindow(screnWidth, screnHeight, "TEST-1", NULL, NULL); glViewport(0, 0, screnWidth, screnHeight); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); id_tex_2d = 0; unsigned char* data = nullptr; loadTexture("img/test_1.png", data, id_tex_2d, textureWidth, textureHeight, channel); generateTexture(screnWidth, screnHeight, textureWidth, textureHeight, id_tex_2d, data); LFRect clip = {0, 0, 100, 100}; while (!glfwWindowShouldClose(window)) { //drawTriangle(window); drawTexture_TEST2(textureWidth, textureHeight, id_tex_2d); //renderTextureClip(-250, -250, textureWidth, textureHeight, id_tex_2d, &clip); //RenderSprite(id_tex_2d, 0, 0, textureWidth, textureHeight, 100, 100, 200, 200); glfwSwapBuffers(window); glfwPollEvents(); } if (data != nullptr) SOIL_free_image_data( data ); glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }
template <unsigned int N> void MRSamplersGL<N>::updateGL(Vec<N, int> window, int nSamples) { if(texture == -1) { return; } #ifdef PIC_DEBUG printf("window: %d %d\n", window[0], window[1]); #endif if(!this->update(window, nSamples)) { return; } glDeleteTextures(1, &texture); generateTexture(); this->oldSamples = nSamples; this->oldWindow = window; }
PathTexture* PathCache::addTexture(const PathDescription& entry, const SkPath *path, const SkPaint* paint) { ATRACE_CALL(); float left, top, offset; uint32_t width, height; computePathBounds(path, paint, left, top, offset, width, height); if (!checkTextureSize(width, height)) return NULL; purgeCache(width, height); SkBitmap bitmap; drawPath(path, paint, bitmap, left, top, offset, width, height); PathTexture* texture = createTexture(left, top, offset, width, height, path->getGenerationID()); generateTexture(entry, &bitmap, texture); return texture; }
void NGLScene::paintGL() { // clear the screen and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0,0,m_width,m_height); //Check for change in render settings from UI if(savemode != renderer->getsaveimage()) { renderer->setSaveImage(savemode); } generateTexture(); //Set Values for window scaling ngl::ShaderLib *shader = ngl::ShaderLib::instance(); shader->use("Render"); //Bind back vertex array object glBindVertexArray(m_vaoID); glBindTexture(GL_TEXTURE_2D,m_textureName); glDrawArrays(GL_TRIANGLES,0,6); }
void PDF::render(const QRectF& texCoords) { if (!pdfPage_) return; // get on-screen and full rectangle corresponding to the window const QRectF screenRect = GLWindow::getProjectedPixelRect(true); const QRectF fullRect = GLWindow::getProjectedPixelRect(false); // if we're not visible or we don't have a valid SVG, we're done... if(screenRect.isEmpty()) { // TODO clear existing FBO for this OpenGL window return; } // generate texture corresponding to the visible part of these texture coordinates generateTexture(screenRect, fullRect, texCoords); if(!texture_.isValid()) return; // figure out what visible region is for screenRect, a subregion of [0, 0, 1, 1] const float xp = (screenRect.x() - fullRect.x()) / fullRect.width(); const float yp = (screenRect.y() - fullRect.y()) / fullRect.height(); const float wp = screenRect.width() / fullRect.width(); const float hp = screenRect.height() / fullRect.height(); // Render the entire texture on a (scaled) unit textured quad glPushMatrix(); glTranslatef(xp, yp, 0); glScalef(wp, hp, 1.f); drawUnitTexturedQuad(); glPopMatrix(); }
void init(void) { generateTexture(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(2, texName); glBindTexture(GL_TEXTURE_2D, texName[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, texName[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, texture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0, 1.0, 1, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(distance * sin(phi) * cos(theta), distance * sin(phi) * sin(theta), distance * cos(phi), 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); glBindTexture(GL_TEXTURE_2D, texName[0]); glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.667f, 1.0f); }
PathTexture* PathCache::get(const SkPath* path, const SkPaint* paint) { path = getSourcePath(path); PathDescription entry(kShapePath, paint); entry.shape.path.mPath = path; PathTexture* texture = mCache.get(entry); if (!texture) { texture = addTexture(entry, path, paint); } else { // A bitmap is attached to the texture, this means we need to // upload it as a GL texture const sp<Task<SkBitmap*> >& task = texture->task(); if (task != NULL) { // But we must first wait for the worker thread to be done // producing the bitmap, so let's wait SkBitmap* bitmap = task->getResult(); if (bitmap) { generateTexture(entry, bitmap, texture, false); texture->clearTask(); } else { ALOGW("Path too large to be rendered into a texture"); texture->clearTask(); texture = NULL; mCache.remove(entry); } } else if (path->getGenerationID() != texture->generation) { // The size of the path might have changed so we first // remove the entry from the cache mCache.remove(entry); texture = addTexture(entry, path, paint); } } return texture; }
void PathCache::generateTexture(const PathDescription& entry, SkBitmap* bitmap, PathTexture* texture, bool addToCache) { generateTexture(*bitmap, texture); uint32_t size = texture->width * texture->height; if (size < mMaxSize) { mSize += size; PATH_LOGD("PathCache::get/create: name, size, mSize = %d, %d, %d", texture->id, size, mSize); if (mDebugEnabled) { ALOGD("Shape created, size = %d", size); } if (addToCache) { mCache.put(entry, texture); } } else { // It's okay to add a texture that's bigger than the cache since // we'll trim the cache later when addToCache is set to false if (!addToCache) { mSize += size; } texture->cleanup = true; } }
int check_keys(XEvent *e, Game *g){ g->mouseThrustOn=false; //keyboard input? static int shift=0; int key = XLookupKeysym(&e->xkey, 0); //Log("key: %i\n", key); if (e->type == KeyRelease) { keys[key]=0; if (key == XK_Shift_L || key == XK_Shift_R) shift=0; if(key == XK_w){ paddle1YVel = 0; paddle1.setYPos(paddle1.getYPos()); } if(key == XK_s){ paddle1YVel = 0; paddle1.setYPos(paddle1.getYPos()); } if(key == XK_o){ paddle2YVel = 0; paddle2.setYPos(paddle2.getYPos()); } if(key == XK_l){ paddle2YVel = 0; paddle2.setYPos(paddle2.getYPos()); } return 0; } if (e->type == KeyPress) { keys[key]=1; if (key == XK_Shift_L || key == XK_Shift_R) { shift=1; return 0; } if(key == XK_Return) { //printf("Enter pressed\n"); createSound2(); hud->setPaused(false); gameStarted = true; hud->setPlayer1Health(100); hud->setPlayer2Health(100); if (is_gameover == true){ hud->setIsShowWelcome(true); gameStarted = false; intro = 0; } else{ hud->setIsShowWelcome(false); init_ball_paddles(); //REINITIALIZE OBSTACLE POSITION AND VELIOCITY: obstacle->setXPos((1250 / 2.0) - 25); obstacle->setYPos(900 / 2.0); obstacle->setYVel(-5.0f); intro = 1; } is_gameover = false; timer.reset(); timer.start(); } if (hud->isShowHelpMenu()==false && hud->isShowWelcome()==false){ if (key == XK_p && hud->isPaused()==true){ hud->setPaused(false); resumeGame(); } else if (key == XK_p && hud->isPaused()==false){ hud->setPaused(true); pauseGame(); } else if (key == XK_q){//to quit out of game hud->setIsShowWelcome(true); hud->setPaused(false); gameStarted = false; intro = 0; } } if (hud->isShowWelcome() == true){ if (key == XK_Left) { bgTexture = generateTexture(bgTexture, bgImage1); selected_screen = LEFT; level = 1; } else if (key == XK_Right) { bgTexture = generateTexture(bgTexture, bgImage2); selected_screen = RIGHT; level = 2; } else if (key == XK_Up) { hud->setAI(false);//player 2 is human paddle2.setCpuPlayer(false); } else if (key == XK_Down){ hud->setAI(true);//player 2 is computer paddle2.setCpuPlayer(true); } else if (key == XK_h) { hud->setIsShowWelcome(false); hud->setIsShowHelpMenu(true); } return 0; } if (hud->isShowHelpMenu() == true){ if (key == XK_b){ //SHOW HELP MENU: hud->setIsShowHelpMenu(false); hud->setIsShowWelcome(true); } } } else { return 0; } float paddleSpeed = 20.0f; if (shift){} switch(key) { case XK_Escape: return 1; case XK_w: paddle1YVel = paddleSpeed; break; case XK_s: paddle1YVel = -paddleSpeed; break; case XK_a: break; case XK_d: break; case XK_o: paddle2YVel = paddleSpeed; break; case XK_l: paddle2YVel = -paddleSpeed; break; } return 0; }
void init_opengl(void) { //OpenGL initialization glViewport(0, 0, xres, yres); //Initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //This sets 2D mode (no perspective) glOrtho(0, xres, 0, yres, -1, 1); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glDisable(GL_CULL_FACE); // //Clear the screen to black glClearColor(0.0, 0.0, 0.0, 1.0); //Do this to allow fonts glEnable(GL_TEXTURE_2D); initialize_fonts(); system("convert ./images/titlescreen.png ./images/titlescreen.ppm"); system("convert ./images/bomb.png ./images/bomb.ppm"); system("convert ./images/game_over.png ./images/game_over.ppm"); system("convert ./images/ninja_robot.png ./images/ninja_robot.ppm"); system("convert ./images/ninja_robot2.png ./images/ninja_robot2.ppm"); system("convert ./images/help_menu.png ./images/help_menu.ppm"); system("convert ./images/explode.png ./images/explode.ppm"); system("convert ./images/paused.png ./images/paused.ppm"); system("convert ./images/portal0.png ./images/portal0.ppm"); system("convert ./images/portal1.png ./images/portal1.ppm"); //Load bomb image(s): bombImage = loadImage(BOMB_IMAGE_PATH.c_str()); bombTexture = generateTransparentTexture(bombTexture, bombImage); explodeImage = loadImage(EXPLODE_IMAGE_PATH.c_str()); explodeTexture = generateTransparentTexture(explodeTexture, explodeImage); //Load Portal images portalImage0 = loadImage(PORTAL_TYPE_0_PATH.c_str()); portalTexture0 = generateTransparentTexture(portalTexture0, portalImage0); portalImage1 = loadImage(PORTAL_TYPE_1_PATH.c_str()); portalTexture1 = generateTransparentTexture(portalTexture1, portalImage1); //Create background texture elements introBG = loadImage(BG_IMAGE_PATH.c_str()); introTexture = generateTexture(introTexture, introBG); bgImage1 = loadImage(BG_IMAGE_PATH1.c_str()); bgTexture = generateTexture(bgTexture, bgImage1); bgTexture1 = generateTexture(bgTexture1, bgImage1); bgImage2 = loadImage(BG_IMAGE_PATH2.c_str()); bgTexture2 = generateTexture(bgTexture2, bgImage2); //Create gameover texture: gameOverImage = loadImage(GAMEOVER_IMAGE_PATH.c_str()); gameOverTexture = generateTexture(gameOverTexture, gameOverImage); //Create help menu texture: helpMenuImage = loadImage(HELP_MENU_IMAGE_PATH.c_str()); helpMenuTexture = generateTexture(helpMenuTexture, helpMenuImage); //Create paused texture: pausedImage = loadImage(PAUSED_IMAGE_PATH.c_str()); pausedTexture = generateTransparentTexture(pausedTexture, pausedImage); //REMOVE PPMS: remove("./images/titlescreen.ppm"); remove("./images/bomb.ppm"); remove("./images/game_over.ppm"); remove("./images/ninja_robot.ppm"); remove("./images/ninja_robot2.ppm"); remove("./images/help_menu.ppm"); remove("./images/explode.ppm"); remove("./images/paused.ppm"); remove("./images/portal0.ppm"); remove("./images/portal1.ppm"); }
void ofxIRGenerator::draw(float x, float y, float w, float h){ generateTexture(); glColor3f(1,1,1); image_texture.draw(x, y, w, h); }
/** Executes test iteration. * * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed. */ tcu::TestNode::IterateResult TextureFilterAnisotropicDrawingTestCase::iterate() { const glw::Functions& gl = m_context.getRenderContext().getFunctions(); bool result = true; GLfloat maxAnisoDegree = 2.0; gl.getFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisoDegree); GLU_EXPECT_NO_ERROR(gl.getError(), "getFloatv"); std::vector<GLfloat> anisoVec; anisoVec.push_back(1.0f); anisoVec.push_back(2.0f); if (maxAnisoDegree > 2.0f) anisoVec.push_back(maxAnisoDegree); for (deUint32 iTarget = 0; iTarget < m_supportedTargets.size(); ++iTarget) { GLenum target = m_supportedTargets[iTarget]; for (deUint32 iFormat = 0; iFormat < m_supportedInternalFormats.size(); ++iFormat) { GLenum format = m_supportedInternalFormats[iFormat]; // Generate texture generateTexture(gl, target); // Fill texture with strips pattern fillTexture(gl, target, format); // Draw scene GLuint lastPoints = 0xFFFFFFFF; for (deUint32 i = 0; i < anisoVec.size(); ++i) { GLfloat aniso = anisoVec[i]; if (result) result = result && drawTexture(gl, target, aniso); // Verify result if (result) { GLuint currentPoints = verifyScene(gl); if (lastPoints <= currentPoints) { m_testCtx.getLog() << tcu::TestLog::Message << "Anisotropy verification failed (lastPoints <= currentPoints) for " << "anisotropy: " << aniso << ", " << "target: " << glu::getTextureTargetName(target) << ", " << "internalFormat: " << glu::getUncompressedTextureFormatName(format) << ", " << "lastPoints: " << lastPoints << ", " << "currentPoints: " << currentPoints << tcu::TestLog::EndMessage; result = false; break; } lastPoints = currentPoints; } } // Release texture releaseTexture(gl); if (!result) { // Stop loops iTarget = m_supportedTargets.size(); iFormat = m_supportedInternalFormats.size(); } } } if (result) m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); else m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); return STOP; }
void Star::generateStar() { radius = 90.0f + rand() % 15; int c = rand() % 3; compositionColor1.red = c == 0 ? 255 : rand() % 75 + 175; compositionColor1.green = c == 1 ? 255 : rand() % 75 + 175; compositionColor1.blue = c == 2 ? 255 : rand() % 75 + 175; compositionColor1.alpha = 255; compositionColor2.red = c == 0 ? 255 : rand() % 75 + 175; compositionColor2.green = c == 1 ? 255 : rand() % 75 + 175; compositionColor2.blue = c == 2 ? 255 : rand() % 75 + 175; compositionColor2.alpha = 255; utils::NoiseMap heightMap = generateHeightMap(); int heightMapHeight = heightMap.GetHeight(); int heightMapWidth = heightMap.GetWidth(); generateTexture(heightMap); vector<Vector3> vertices; vector<Vector3> normales; vector<Vector2> uvs; const int nbLong = 24; const int nbLat = 16; const int nbVertices = (nbLong + 1) * nbLat + 2; Vector3 vector3Up = makeVector3(0.0f, 1.0f, 0.0f); #pragma region Vertices vertices = std::vector<Vector3>(nbVertices); const float _pi = M_PI; const float _2pi = _pi * 2.0f; vertices[0] = scalerMultiplyVector3(vector3Up, radius); for (int lat = 0; lat < nbLat; ++lat) { float a1 = _pi * float(lat + 1) / (nbLat + 1); float sin1 = sin(a1); float cos1 = cos(a1); for (int lon = 0; lon <= nbLong; ++lon) { float a2 = _2pi * float(lon == nbLong ? 0 : lon) / nbLong; float sin2 = sin(a2); float cos2 = cos(a2); int heightX = int(float(lon) / (nbLong)* heightMapWidth); int heightY = int(float(lat) / (nbLat)* heightMapHeight); if (lon == nbLong) heightX = 0; //float height = heightMap.GetValue(heightX, heightY) * radius * 0.05f; vertices[lon + lat * (nbLong + 1) + 1] = scalerMultiplyVector3(makeVector3(sin1 * cos2, cos1, sin1 * sin2), radius); } } vertices[nbVertices - 1] = scalerMultiplyVector3(vector3Up, -radius); #pragma endregion #pragma region Normales normales = std::vector<Vector3>(nbVertices); for (int n = 0; n < nbVertices; n++) normales[n] = normalizeVector3(vertices[n]); #pragma endregion #pragma region UVs uvs = std::vector<Vector2>(nbVertices); uvs[0] = makeVector2(1.0f, 1.0f); uvs[nbVertices - 1] = makeVector2(0.0f, 0.0f); for (int lat = 0; lat < nbLat; lat++) for (int lon = 0; lon <= nbLong; lon++) uvs[lon + lat * (nbLong + 1) + 1] = makeVector2((float)lon / nbLong, 1.0f - (float)(lat + 1) / (nbLat + 1)); #pragma endregion #pragma region Triangles const int nbFaces = nbVertices; const int nbTriangles = nbFaces * 2; const int nbIndexes = nbTriangles * 3; triangles = std::vector<GLuint>(nbIndexes); //Top Cap int i = 0; for (int lon = 0; lon < nbLong; ++lon) { triangles[i++] = lon + 2; triangles[i++] = lon + 1; triangles[i++] = 0; } //Middle for (int lat = 0; lat < nbLat - 1; ++lat) { for (int lon = 0; lon < nbLong; ++lon) { int current = lon + lat * (nbLong + 1) + 1; int next = current + nbLong + 1; triangles[i++] = current; triangles[i++] = current + 1; triangles[i++] = next + 1; triangles[i++] = current; triangles[i++] = next + 1; triangles[i++] = next; } } //Bottom Cap for (int lon = 0; lon < nbLong; ++lon) { triangles[i++] = nbVertices - 1; triangles[i++] = nbVertices - (lon + 2) - 1; triangles[i++] = nbVertices - (lon + 1) - 1; } Vnu = std::vector<VertexDataPNT>(nbVertices); for (int i = 0; i < nbVertices; ++i) { VertexDataPNT pnt; pnt.positionCoordinates = vertices[i]; pnt.normalCoordinates = normales[i]; pnt.textureCoordinates = uvs[i]; Vnu[i] = pnt; } #pragma endregion }