Scene::Scene(int w,int h):width(w),height(h),scale(1.0),fb(0),textureHandle(0),checkboard_width(256),checkboard_height(256) { // Initialize GL state. // glHint(GL_PEr, GL_FASTEST); glEnable(GL_CULL_FACE); // glShadeModel(GL_SH); glDisable(GL_DEPTH_TEST); // Init the shaders // gProgramHandle = createProgram( gVertexShader, gPixelShader ); programHandle = createProgram( "shaders/vertexShader", "shaders/fragmentShader" ); Log("Program handle %d",programHandle); if( !programHandle ) { LogError( "Could not create program." ); assert(0); } // // Read attribute locations from the program aPositionHandle = glGetAttribLocation( programHandle, "aPosition" ); Log("gaPositionHandle %d",aPositionHandle); CheckGlError( "glGetAttribLocation" ); // aTexCoordHandle = glGetAttribLocation( programHandle, "aTexCoord" ); Log("gaTexCoordHandle %d",aTexCoordHandle); CheckGlError( "glGetAttribLocation" ); aTexSamplerHandle = glGetUniformLocation( programHandle, "sTexture" ); Log("gaTexSamplerHandle %d",aTexSamplerHandle); CheckGlError( "glGetUnitformLocation" ); GLubyte* pixels = generateCheckBoardTextureData(checkboard_width,checkboard_height,3); GLubyte* resizedPointer = (GLubyte*)scaleTexture(1.0,pixels,checkboard_width,checkboard_height,GL_RGB,GL_UNSIGNED_BYTE); /* * Do whatever you want with resized texture data pointer */ delete resizedPointer; delete pixels; glViewport(0,0,width,height); }
void TextureSystem::retexture(entityx::Entity e) { //Add a texture component if it is not there. Lazy initialization if(!e.has_component<TextureComponent>()) { e.assign<TextureComponent>(sf::Sprite()); } /* Use the texturemap on the type the ent was spawned with to choose a random texure. * Then, the new texture needs to be scaled to the Box2D component */ auto textureComponent = e.component<TextureComponent>(); auto spawnShape = e.component<SpawnComponent>()->type; auto& textureBank = texturemap.at(spawnShape).first; sf::Sprite& s = textureComponent->sprite; s.setTexture(textureBank->at(rand() % (randomTexturesEnabled ? textureBank->size() : 1)), true); scaleTexture(e); //Set font info sf::Text& text = textureComponent->positionText; text.setFont(boxFont); text.setCharacterSize(12); }