简体   繁体   中英

OpenGL Texture Loading Predicament

OK, so I made a library that handles basic OpenGL rendering. It contains three buffers, one for vertices, uv's and normals. In the main render function is where I bind the buffers, enable vertex attributes, and then call glDrawArrays(). But I ran into an unexpected issue that is more engineering based then code based which is that I can only bind one texture at a time. So all the vertices will have the same textures when I draw them, How can I get around this? If you need any more source I will post it.

Main Render Function

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,this->_VBO);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER,this->_TBO);
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER,this->_NBO);

glDrawArrays(GL_TRIANGLES,0,this->polyCount);

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);

Buffers:

//Designated Vertex Buffer
    std::array<GLfloat,BUFFER_SIZE> BUFFER_1;
    UINT bufferIndex1;

    //Designated Normal Buffers
    std::array<GLfloat,BUFFER_SIZE> BUFFER_2;
    UINT bufferIndex2;

    //Designated UV Buffer
    std::array<GLfloat,BUFFER_SIZE> BUFFER_3;
    UINT bufferIndex3;

What we would normally do here is split the mesh up into sub-meshes, by "material". An object with a different texture is technically a different material, so you would render it separately. You can render a single mesh using multiple textures by using something called an Atlas. That is to say, you pack your textures into a single bitmap and choose texture coordinates within that bitmap depending on the texture you want to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM