Ok, I will show you all steps I do, with results of program. I attached two files. One is the texture I want to use (it is used for testing purposes;)) and the another one is program result.
To answer the question DarkPhoton asked me, I want one texture on each quad. If this is wrong idea just tell me
First of all, used classes:
C_point{
public:
GLfloat x, y, z;
}
C_texcoord{
public:
GLfloat u,v;
}
Grid is defined as:
C_point nodes[xNodes][yNodes]; //where xNodes=yNodes=3
Next thing I need is array of indices. I`ve assumed grid points numeration as follows:
2-5-8
| | |
1-4-7
| | |
0-3-6
In this case indices is array of 16 size. Points are set as follows:
3,4,1,0 4,5,2,1 6,7,4,3 7,8,5,4
First of all, function that builds vbo:
#define A 0.f, 0.f
#define B 0.f, 1.f
#define C 1.f, 1.f
#define D 1.f, 0.f
C_texcoord coords[16];
BuildVBO(){
//setting texture coordinates
//according to the indices, I wonder if the texture coordinates shouldn`t be in order D, C, B, A, but looks even worse than the picure i attached.
coords[0].set(A);
coords[1].set(B);
coords[2].set©;
coords[3].set(D);
coords[4].set(A);
coords[5].set(B);
coords[6].set(C);
coords[7].set(D);
coords[8].set(A);
coords[9].set(B);
coords[10].set(C);
coords[11].set(D);
coords[12].set(A);
coords[13].set(B);
coords[14].set(C);
coords[15].set(D);
C_point _nodes[9];
//this is to make sure that points are in order I want them to be
int i=0;
for (int x=0;x<xNodes;x++){
for (int y=0;y<yNodes;y++){
_nodes[i] = nodes[x][y];
i++;
}
}
//grid
glGenBuffersARB(1, &id_VBO_vertices);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, id_VBO_vertices);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, xNODESyNODES3*sizeof(GLfloat),_nodes, GL_STATIC_DRAW_ARB );
//texture
glGenBuffersARB(1, &id_VBO_texture);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, id_VBO_texture);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, _SIZE*sizeof(GLfloat),coords, GL_STATIC_DRAW_ARB );
}
And next - drawing function.
Draw(){
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
// glEnableClientState( GL_COLOR_ARRAY ); // Enable Vertex Array
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable textures
//BuildVBO();
// glBindBufferARB(GL_ARRAY_BUFFER,id_VBO_colors);
// glColorPointer( 3, GL_FLOAT, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER,id_VBO_vertices);
glVertexPointer( 3, GL_FLOAT, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, id_VBO_texture);
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL);
//glDrawElements( GL_TRIANGLES, indices_size, GL_UNSIGNED_INT, indices );
glDrawElements( GL_QUADS, indices_size, GL_UNSIGNED_INT, indices );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
//glDisableClientState( GL_COLOR_ARRAY );
SDL_GL_SwapBuffers();
}
I hope I am clear enough