Hello
I generated a terrain and I want texture it.
My vertex shader is like that :
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (location = 2) in vec2 texCoord;
out vec2 TexCoord;
out vec3 ourColor;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f);
ourColor = color;
TexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
}
My fragment shader is like that :
#version 330 core
out vec4 color;
uniform sampler2D ourTexture1;
uniform sampler2D ourTexture2;
in vec2 TexCoord;
void main()
{
color = texture(ourTexture1, TexCoord);
}
I have all the terrain’s vertices in a vector.
I don’t know how to store texture coordinates. I guess in another vector but i think there will be an issue with
glVertexAttribPointer
call.
I mean, in the vertices vector, there is no texture coordinates so how will I call glVertexAttribPointer when i’ll just want render the terrain ? and i’ll just want render the texture ?
My code is like that in the case of vertices, color and texture coordinates are in the same vector and VBO.
glVertexAttribPointer(0, 3, GL_FLOAT, GL_TRUE, 8 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
// Color attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
// TexCoord attribute
glVertexAttribPointer(2, 2, GL_FLOAT, GL_TRUE, vertices_terrain.size() * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(2);
En résumé : I want separate vertices and color, texture coordinates.
Because of shaders and my architecture, there will be not be colors, texture and position at every call. Am I right ?
If you don’t understand tell me !
Thanks a lot