Sign in to follow this  
JoshuaWaring

One method of drawing works and another doesnt

Recommended Posts

I have two sections of code and one doesn't work which leaves me to question why. I'm using OpenGL 4.1 in the program and drawing with itemediate doesn't affect anything. The purpse of the function is to draw a texture at a position provided, the first drawing code in the snippet is something I ripped of the interwebs to see if it was drawing or some other problem I was having.

	static const GLfloat g_vertex_buffer_data[] = {
		-1.0f, -1.0f, 0.0f,
		1.0f, -1.0f, 0.0f,
		0.0f,  1.0f, 0.0f,
	};

	// This will identify our vertex buffer
	GLuint vertexbuffer;

	// Generate 1 buffer, put the resulting identifier in vertexbuffer
	glGenBuffers(1, &vertexbuffer);

	// The following commands will talk about our 'vertexbuffer' buffer
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

	// Give our vertices to OpenGL.
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	glVertexAttribPointer(
		0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
		3,                  // size
		GL_FLOAT,           // type
		GL_FALSE,           // normalized?
		0,                  // stride
		(void*)0            // array buffer offset
		);

	// Draw the triangle !
	glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

	glDisableVertexAttribArray(0);

	 

	//glEnable(GL_TEXTURE_2D);
	//glBindTexture(GL_TEXTURE_2D, tex.textureID);

	glBegin(GL_QUADS);

	glVertex3d(position.x, position.y, position.z);
	//glTexCoord2i(0,0);
	glVertex3d(position.x + tex.width, position.y, position.z);
	//glTexCoord2i( 1,0);
	glVertex3d(position.x + tex.width, position.y + tex.height, position.z);
	//glTexCoord2i( 1, 1);
	glVertex3d(position.x, position.y + tex.height, position.z);
	//glTexCoord2i(0, 1);

	glEnd(); 

	//glDisable(GL_TEXTURE_2D);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this