The problem of multitexturing (beginner)

I am new to OpenGL and mobile programming in general.

I am trying to load 2 textures and show them on the same object (I mean one set of faith) with different coordinates.

My approach:

glGenTextures(2, &textures[0]);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTexture(GL_TEXTURE0);
glClientActiveTexture( GL_TEXTURE0 );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexCoordPointer(2, GL_SHORT, 0, mapTextCoords);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, map.width, map.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [map getByteData]);

glActiveTexture(GL_TEXTURE1);
glClientActiveTexture( GL_TEXTURE1 );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexCoordPointer(2, GL_SHORT, 0, backgroundTextCoords);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, background.width, background.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [background getByteData]);

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, mapVertices);

What am I doing wrong? And what should I do next?

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glDrawArrays(GL_TRIANGLE_STRIP, 0, BYTES_PER_PIXEL);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

As a result, I got a white object (no textures at all).

+3
source share
2 answers

Try providing a complete set of mipmaps if you intend to use GL_TEXTURE_MIN_FILTER default GL_NEAREST_MIPMAP_LINEAR .

Or set GL_TEXTURE_MIN_FILTERto GL_NEAREST/ GL_LINEAR.

+2
source

To initialize, try:

glGenTextures(1, &texA);
glBindTexture(GL_TEXTURE_2D, texA);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_t, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, lod, GL_RGB, pixWidth, pixHeight, 0, GL_RGB, GL_FLOAT, pixelData);
glGenerateMipmap(GL_TEXTURE_2D);

Modify the above as needed for your specific needs and repeat for the second texture.

To paint, try:

// Bind textures
glActiveTexture(GL_TEXTURE0+i);        // set which texture unit will be affected by subsequent glBindTexture
glBindTexture(GL_TEXTURE_2D, texA);    // bind a 2D texture
glActiveTexture(GL_TEXTURE0+i);        // set a different texture unit than above
glBindTexture(GL_TEXTURE_2D, texB);    // bind another 2D texture

// Set texcoords for first texture
glClientActiveTexture(GL_TEXTURE0+i);  // set which texture unit will be affected by subsequent
                                       // call to glTexCoordPointer (should match what you
                                       // gave glActiveTexture for texA earlier)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);  // enable texcoord attributes
glTexCoordPointer(...);                // pass the texcoord array for texA

// Set texcoords for second texture
glClientActiveTexture(GL_TEXTURE0+i);  // set which texture unit will be affected by subsequent
                                       // call to glTexCoord pointer (should match what you
                                       // gave glActiveTexture for texB earlier)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(...);    // pass the texcoord array for texB

. , , GL_TEXTURE1, GL_TEXTURE2 .., GL_TEXTURE0+i, - 0 - GL_MAX_TEXTURE_COORDS.

0

Source: https://habr.com/ru/post/1785643/


All Articles