Possible to make 4 different pictures in a square?
Is it possible make different picture in each corner of a square? (4 different picture on a square) Some people misunderstood my last message I posted. So I had to make it more clear. If you know how to make it please post your code here. If theres tutorial pls post it here too.
Waldoo
Either break the quad into four smaller quads, and draw them with it''s own texture, or combine the four images into one before uploading them to OpenGL. I suggest you go for the first one. There''s no way to get OpenGL to use different textures on different parts of one single primitive.
Waldoo, please don''t flame against those who try to help you, or else nobody will want to help you 
Bob doesn''t know that you are a newbie. Before you told it, how could we know ?
In some forums, newbies begin each post by the word *NEWBIE* in order to claim that detailed information is needed. You should try that, otherwise don''t expect to have information with as much detail as you look for.
As for being on topic, I won''t post here since the other thread seems to be living...

Bob doesn''t know that you are a newbie. Before you told it, how could we know ?
In some forums, newbies begin each post by the word *NEWBIE* in order to claim that detailed information is needed. You should try that, otherwise don''t expect to have information with as much detail as you look for.
As for being on topic, I won''t post here since the other thread seems to be living...
Could you please post example or tutorial here as requested previously. I am newbie and I need to see the whole thing to understand better.
Waldoo
Waldoo
you just have to split your quad and it might work.
let''s say your quad is like that :
You know vertex coordinates A, B, C and D.
OpenGL drawing command may be :
GLfloat A[3] = { /* Write the coordinates of A here */ };
GLfloat B[3] = { /* Write the coordinates of B here */ };
GLfloat C[3] = { /* Write the coordinates of C here */ };
GLfloat D[3] = { /* Write the coordinates of D here */ };
GLuint texture = /* The texture ID is here */;
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(A);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(B);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(D);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(C);
glEnd();
/* Note: be careful of the order the the vertices : it is ABDC with GL_QUADS,
but it would be ABCD with GL_QUAD_STRIP */
To split the quad, you have to compute the vertex coordinates E, F, G, H and I and connect the quads as shown below :
corresponding OpenGL drawing command may be :
#define COMPUTE_MIDDLE(_dst,_src1,_src2) {_dst[0]=0.5f*(_src1[0]+_src2[0]);\
_dst[1]=0.5f*(_src1[1]+_src2[1]);\
_dst[2]=0.5f*(_src1[2]+_src2[2]);}
GLfloat A[3] = { /* Write the coordinates of A here */ };
GLfloat B[3] = { /* Write the coordinates of B here */ };
GLfloat C[3] = { /* Write the coordinates of C here */ };
GLfloat D[3] = { /* Write the coordinates of D here */ };
GLfloat E[3], F[3], G[3], H[3], I[3];
GLuint texture[4] = { /* The texture IDs are here */ };
COMPUTE_MIDDLE(E,A,B);
COMPUTE_MIDDLE(F,A,C);
COMPUTE_MIDDLE(G,A,D);
COMPUTE_MIDDLE(H,B,D);
COMPUTE_MIDDLE(I,C,D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(A);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(E);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(G);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(F);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(E);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(B);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(H);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(G);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(F);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(G);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(I);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(C);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[3]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(G);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(H);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(D);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(I);
glEnd();
/*Be careful : now the texture id is in an array. */
Hope that was the kind of help you looked for.
let''s say your quad is like that :
|
You know vertex coordinates A, B, C and D.
OpenGL drawing command may be :
GLfloat A[3] = { /* Write the coordinates of A here */ };
GLfloat B[3] = { /* Write the coordinates of B here */ };
GLfloat C[3] = { /* Write the coordinates of C here */ };
GLfloat D[3] = { /* Write the coordinates of D here */ };
GLuint texture = /* The texture ID is here */;
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(A);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(B);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(D);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(C);
glEnd();
/* Note: be careful of the order the the vertices : it is ABDC with GL_QUADS,
but it would be ABCD with GL_QUAD_STRIP */
To split the quad, you have to compute the vertex coordinates E, F, G, H and I and connect the quads as shown below :
|
corresponding OpenGL drawing command may be :
#define COMPUTE_MIDDLE(_dst,_src1,_src2) {_dst[0]=0.5f*(_src1[0]+_src2[0]);\
_dst[1]=0.5f*(_src1[1]+_src2[1]);\
_dst[2]=0.5f*(_src1[2]+_src2[2]);}
GLfloat A[3] = { /* Write the coordinates of A here */ };
GLfloat B[3] = { /* Write the coordinates of B here */ };
GLfloat C[3] = { /* Write the coordinates of C here */ };
GLfloat D[3] = { /* Write the coordinates of D here */ };
GLfloat E[3], F[3], G[3], H[3], I[3];
GLuint texture[4] = { /* The texture IDs are here */ };
COMPUTE_MIDDLE(E,A,B);
COMPUTE_MIDDLE(F,A,C);
COMPUTE_MIDDLE(G,A,D);
COMPUTE_MIDDLE(H,B,D);
COMPUTE_MIDDLE(I,C,D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(A);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(E);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(G);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(F);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(E);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(B);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(H);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(G);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(F);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(G);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(I);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(C);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[3]);
glBegin(QL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3fv(G);
glTexCoord2f(1.0f, 1.0f); glVertex3fv(H);
glTexCoord2f(1.0f, 0.0f); glVertex3fv(D);
glTexCoord2f(0.0f, 0.0f); glVertex3fv(I);
glEnd();
/*Be careful : now the texture id is in an array. */
Hope that was the kind of help you looked for.
Yes thank you. I have one more question how do you load several images for array glBindTexture?
Waldoo
Waldoo
To generate textures in OpenGL, do this :
GLuint texture[4];
glGenTextures(4, &texture[0]);
it will create 4 textures in OpenGL.
To initialize them, do this :
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2d(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (const GLvoid*)pixels);
where width is the width (in pixels) of the first texture (eg texture[0]), height is the height (in pixels) of the first texture, and pixels is an array of bytes which contain RGB information of the texture : GLubyte pixels[height][width][3];
Repeat the same operation for the 3 other textures :
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2d(...
Note that you will probably have different width and height for each texture.
Important : height and width must be a power of two (eg, something like 16, 32, 256, etc, but NOT something like 100, 200 or 500).
GLuint texture[4];
glGenTextures(4, &texture[0]);
it will create 4 textures in OpenGL.
To initialize them, do this :
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2d(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (const GLvoid*)pixels);
where width is the width (in pixels) of the first texture (eg texture[0]), height is the height (in pixels) of the first texture, and pixels is an array of bytes which contain RGB information of the texture : GLubyte pixels[height][width][3];
Repeat the same operation for the 3 other textures :
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2d(...
Note that you will probably have different width and height for each texture.
Important : height and width must be a power of two (eg, something like 16, 32, 256, etc, but NOT something like 100, 200 or 500).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement