Nothing showing OpenGL 3.3

To be honest I'm a total noob at the newer OpenGL versions... after finally convincing myself that I should give up the depreciated versions I've been running into issues when I'm trying to rewrite rendering code. Nothing is showing up at all.

I can't narrow this down anymore and I have completely no idea what I'm doing.

Global matrices:
1
2
		glm::mat4 projection_matrix;
		glm::mat4 view_matrix; // Camera 


The projection matrix is the only thing modified:
projection_matrix = glm::perspective(45.0f, (float)mode.width / mode.height, 0.1f, 100.0f);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
		void Context::draw(const mesh_t& mesh, const material_t& material, const vector3d_t& position)
		{
			const auto& buffer  = mesh.vbo;
			const auto& program = material.shader.glsl.id;

			glm::mat4 model_matrix(1.0f);

			glm::mat4 mvp_matrix;

			debug::check_assertion(glIsProgram(program) == GL_TRUE, "Invalid shader program.");

			handle_gl_error();

			glUseProgram(program);
			
			handle_gl_error();

			const GLuint vert = glGetAttribLocation(program, "vertex");
			const GLuint tex  = glGetAttribLocation(program, "texture_coord");
			const GLuint diffuse_texture = glGetUniformLocation(program, "diffuse_texture");
			const GLuint mvp  = glGetUniformLocation(program, "mvp_matrix");

			model_matrix = glm::translate(model_matrix, glm::vec3(position.x, position.y, position.z));

			mvp_matrix = projection_matrix * view_matrix * model_matrix;

			glUniformMatrix4fv(mvp, 1, GL_FALSE, glm::value_ptr(mvp_matrix));

			handle_gl_error();

			// Expose diffuse texture
			bind_texture(material.diffuse.handle);
			handle_gl_error();

			glActiveTexture(GL_TEXTURE0);
			handle_gl_error();
			glUniform1i(diffuse_texture, 0);
			handle_gl_error();

			// Bind VBO
			glBindBuffer(GL_ARRAY_BUFFER, buffer);
			handle_gl_error();

			// Enable VAOs
			glEnableVertexAttribArray(tex);
			glEnableVertexAttribArray(vert);

			// Texture coordinates
			glBindVertexArray(mesh.texture_coords);
			handle_gl_error();
			glVertexAttribPointer(tex, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), ((void*)sizeof(vector3d_t)));
			handle_gl_error();

			// Vertices
			glBindVertexArray(mesh.vertices);
			handle_gl_error();
			glVertexAttribPointer(vert, 3, GL_FLOAT, GL_FALSE, (sizeof(vertex_t) - sizeof(vector3d_t)), nullptr);
			handle_gl_error();

			glDrawArrays(GL_TRIANGLES, 0, 3);

			glDisableVertexAttribArray(vert);
			glDisableVertexAttribArray(tex);

			glBindVertexArray(0);
		}


Vertex Shader:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#version 150

in vec3 vertex;
in vec2 texture_coord;

out vec2 frag_texture_coord;

uniform mat4 mvp_matrix;

void main()
{
	gl_Position = mvp_matrix * vec4(vertex, 1);
	
	frag_texture_coord = texture_coord;
}


Fragment Shader:
1
2
3
4
5
6
7
8
9
10
11
#version 150

in vec2  frag_texture_coord; 
out vec4 output_color; 

uniform sampler2D diffuse_texture;

void main() 
{ 
   output_color = texture2D(diffuse_texture, frag_texture_coord); 
}
Last edited on
Bump.
closed account (10X9216C)
For glVertexAttribPointer, your stride looks wrong. If your vertex looks something like this:

1
2
3
4
5
6
struct Vertex
{
    Vec3 position;
    Vec2 uv;
};


The stride should be the same for both the functions, sizeof(Vertex).
I fixed that, and it still doesn't do anything. My code now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
		void Context::draw(const mesh_t& mesh, const material_t& material, const vector3d_t& position)
		{
			const auto& buffer  = mesh.vbo;
			const auto& program = material.shader.glsl.id;

			glm::mat4 model_matrix(1.0f);

			glm::mat4 mvp_matrix;

			debug::check_assertion(glIsProgram(program) == GL_TRUE, "Invalid shader program.");

			handle_gl_error();

			glUseProgram(program);
			
			handle_gl_error();

			const GLuint vert = glGetAttribLocation(program, "vertex");
			const GLuint tex  = glGetAttribLocation(program, "texture_coord");
			const GLuint diffuse_texture = glGetUniformLocation(program, "diffuse_texture");
			const GLuint mvp  = glGetUniformLocation(program, "mvp_matrix");

			model_matrix = glm::translate(model_matrix, glm::vec3(position.x, position.y, position.z));

			mvp_matrix = projection_matrix * view_matrix * model_matrix;

			glUniformMatrix4fv(mvp, 1, GL_FALSE, glm::value_ptr(mvp_matrix));

			handle_gl_error();

			// Expose diffuse texture
			bind_texture(material.diffuse.handle);
			handle_gl_error();

			glActiveTexture(GL_TEXTURE0);
			handle_gl_error();
			glUniform1i(diffuse_texture, 0);
			handle_gl_error();

			// Bind VBO
			glBindBuffer(GL_ARRAY_BUFFER, buffer);
			handle_gl_error();

			// Enable VAOs
			glEnableVertexAttribArray(tex);
			glEnableVertexAttribArray(vert);

			// Texture coordinates
			glBindVertexArray(mesh.texture_coords);
			handle_gl_error();
			glVertexAttribPointer(tex, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), ((void*)sizeof(vector3d_t)));
			handle_gl_error();

			// Vertices
			glBindVertexArray(mesh.vertices);
			handle_gl_error();
			glVertexAttribPointer(vert, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_t), nullptr);
			handle_gl_error();

			// Draw the entire mesh
			glDrawArrays(GL_TRIANGLES, 0, mesh.num_vertices);

			glDisableVertexAttribArray(vert);
			glDisableVertexAttribArray(tex);

			glBindVertexArray(0);
		}
Topic archived. No new replies allowed.