Jump to content
  • Advertisement
Sign in to follow this  
htmlboss

Rendering multiple textures on sprite

This topic is 973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With the draw loop for the asteroids, how would I change the active texture to the image texture found at the filepath that I pass to the Asteroid constructor? void MainGame::prepareTextures() { //compile shaders and get Texlocations initShaders("Shaders/background.vert", "Shaders/background.frag"); GLint TexLoc = _colorProgram.getUniformLocation("bgTexture"); glActiveTexture(GL_TEXTURE0); } void MainGame::drawGame() { ... //Asteroids m_spriteBatch.Begin(); //draw asteroids for (int i = 0; i < m_asteroids.size(); i++) { m_asteroids.draw(m_spriteBatch); } m_spriteBatch.End(); m_spriteBatch.renderbatch(); ... } void Asteroids::draw(Engine::SpriteBatch& spriteBatch) { glm::vec4 uv(0.0f, 0.0f, 1.0f, 1.0f); //convert m_imgNum to string and remove trailing zeros std::string strImgNum = std::to_string(m_imgNum); strImgNum.erase(strImgNum.find_last_not_of('0') + 1, std::string::npos); //construct filpath std::string filePath = m_dir + strImgNum + ".png"; static Engine::GLTexture texture = Engine::ResourceManager::GetTexture(filePath, 0, 0, 32, 4); Engine::Color color; color.r = 255; color.g = 255; color.b = 255; color.a = 255; glm::vec4 posAndSize = glm::vec4(m_posX, m_posY, m_width, m_height); spriteBatch.Draw(posAndSize, uv, texture.id, 0.0f, color); } void SpriteBatch::renderbatch() { glBindVertexArray(m_vao); for (unsigned int i = 0; i < m_renderBatches.size(); i++) { glBindTexture(GL_TEXTURE_2D, m_renderBatches.texture); glDrawArrays(GL_TRIANGLES, m_renderBatches.offset, m_renderBatches.numVertices); } glBindVertexArray(0); } }

Share this post


Link to post
Share on other sites
Advertisement


glBindTexture(GL_TEXTURE_2D, m_renderBatches.texture);

just change it here for another array member, of course, have the texture resource already created, just as the original texture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!