1
Sources Generales / Re: takumi12 - VAO (Vertex Array Object) SHADER MAIN 5.2
« Posteado: March 28, 2025, 11:25:21 PM »You're missing the important part that was already mentioned earlier:
"The problem remains how to load the shader and correctly position the transformation values for the camera, view, and model." – takumi12
If your model doesn’t appear, it's not the shader itself — it's likely that your camera/view/projection setup is wrong, and the object is rendered outside the visible space.Code: [Select]void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)
{
const auto texture = Bitmaps.GetTexture(textureIndex);
if (!texture) return;
GLuint textureID = texture->TextureNumber;
if (!glIsTexture(textureID)) return;
glm::mat4 model = glm::mat4(1.0f);
float distanceBehind = -1.0f;
float heightAbove = 0.9f;
float yaw = -0.8;// glm::radians(CameraAngle[0])* glm::radians(CameraFOV);
glm::vec3 characterPosition = glm::vec3(CameraPosition[0], CameraPosition[1], CameraPosition[2]);
glm::vec3 behindOffset = glm::vec3(
cosf(yaw) * -distanceBehind,
sinf(yaw) * -distanceBehind,
0.0f
);
glm::vec3 cameraPosition = characterPosition + behindOffset;
cameraPosition.z += heightAbove;
glm::mat4 view = glm::lookAt(
cameraPosition,
characterPosition,
glm::vec3(0.0f, 0.0f, 1.0f)
);
glm::mat4 projection = glm::perspective(glm::radians(CameraFOV),
(float)WindowWidth / (float)WindowHeight, CameraViewNear, CameraViewFar * 1.4f);
GLuint shader_id = gShaderGL->GetShaderId();
glUseProgram(shader_id);
// Matrici al vertex shader
glUniformMatrix4fv(glGetUniformLocation(shader_id, "model"), 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "view"), 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(shader_id, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
// Texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glUniform1i(glGetUniformLocation(shader_id, "texture1"), 0);
glBindVertexArray(m->VAO);
// Vertex
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_Vertices);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec3_t), vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);
// Texture Coord
glBindBuffer(GL_ARRAY_BUFFER, m->VBO_TexCoords);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_index * sizeof(vec2_t), textCoords);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
// Draw call
glDrawElements(GL_TRIANGLES, vertex_index, GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
glUseProgram(0);
}
Use this hardcoded snippet to test and adjust until your object becomes visible.
exactly like that , the transfom from camera pos is taken from the character's position and it is always returned to BodyOrigin
Samuel
Where do I call this function? void BMD::RenderVertexBuffer(int textureIndex, Mesh_t* m, int vertex_index, vec3_t* vertices, vec2_t* textCoords)