c++ - How to render multiple textures? -
i'm trying understand how render multiple textures different objects in opengl. decided try it, far i'm aware glactivate used select right texture, doesn't work expected it. in code, 2 objects shown (in turns) have same texture. texture initialization part of code:
bool (some args, unsigned int textureunit, bool wrap) { // code opengl->glactivetexture (gl_texture0 + textureunit); glgentextures (1, &textureid); glbindtexture (gl_texture_2d, textureid); glteximage2d (gl_texture_2d, 0, gl_rgba, width, height, 0, gl_bgra, gl_unsigned_byte, targaimage); if (wrap) { gltexparameteri (gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri (gl_texture_2d, gl_texture_wrap_t, gl_repeat); } else { 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); opengl->glgeneratemipmap (gl_texture_2d); }
textureunit 0 first texture, , 1 second. model rendering code:
{ opengl->glbindvertexarray (vertexarrayid); gldrawelements (gl_triangles, indexcount, gl_unsigned_int, 0); }
putting glactive between part, or before part doesn't change thing. question is, how render multiple textures? should put glactivate somewhere else or need change else.
there misunderstanding here, glactivetexture calls managing multiple textures when drawing same object. different objects, bind different texture. remove call activetexture when setting textures (or make sure on 0 when drawing). then, when drawing:
{ opengl->glbindvertexarray (vertexarrayid); glbindtexture(gl_texture_2d, textureid); /* has set somehow */ gldrawelements (gl_triangles, indexcount, gl_unsigned_int, 0); }
Comments
Post a Comment