Jump to content
  • Advertisement
Sign in to follow this  

Texturing a VBO

This topic is 2158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

! New question at bottom !


I've been wanting to draw a quad and have it textured, but this seems to be a larger struggle than I first thought it would of been.

I create my quad and they appear nicely on the screen, in a plain white colour... which is the problem, I can't change that. (Well I can, but I don't know how), Things might me a bit messy because I've been trying alsorts of things on it. Even read the Specifications, but that doesn't really help me on how it operates as a whole.


The code is inside a function and is passed a Vector and a Texture


At the bottom I do infact recieve a error of GL_INVALID_ENUM

const GLdouble vertex_buffer[] = {
        (position.x / windowSizeHalf.x) - 1, (position.y / windowSizeHalf.y) - 1, position.z,
        ((position.x + tex.width) / windowSizeHalf.x) - 1, (position.y / windowSizeHalf.y) - 1, position.z,
        (position.x / windowSizeHalf.x) - 1 , ((position.y + tex.height) / windowSizeHalf.y) - 1, position.z,
        ((position.x + tex.width) / windowSizeHalf.x) - 1, ((position.y + tex.height) / windowSizeHalf.y) - 1, position.z    

    const GLint uv_buffer[] = {
        0, 0,
        1, 0,
        1, 1,
        0, 1

    unsigned int VertexBufferObject[1];
    unsigned int UVBufferObject[1];

    glBindTexture(GL_TEXTURE_2D, tex.textureID);

    glGenBuffers(1, UVBufferObject);
    glGenBuffers(1, VertexBufferObject);

    glBindBuffer(GL_ARRAY_BUFFER, *UVBufferObject);
    glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(unsigned int), uv_buffer, GL_STATIC_DRAW);
    glTexCoordPointer(1, GL_INT, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, *VertexBufferObject);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), vertex_buffer, GL_STATIC_DRAW);
    glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 0, 0);


    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);



    GLenum error = glGetError();
    if(states.RENDERING_DEBUGGING && error != GL_NO_ERROR)


Thank you for any help

Edited by Joshhua5

Share this post

Link to post
Share on other sites

I don't believe that to be correct because that line is fine. I'd say it is coming from before that. Verify that the error is in fact 0 before that line.

Share this post

Link to post
Share on other sites

    glEnable(GL_TEXTURE_2D); // 1280
    glEnableClientState(GL_TEXTURE_COORD_ARRAY); // 1282
    glClientActiveTexture(GL_TEXTURE0); // 1282
    glBindTexture(GL_TEXTURE_2D, tex.textureID); // 0


in the comments are the errors returns. something doesn't seem right


I removed the lines that get the error, but after each command I check an error so the next command is a new error.

Edited by Joshhua5

Share this post

Link to post
Share on other sites

And what about before the first line? Is it actually zero before entering that function in the first place?


Or, are you perhaps using a post-OpenGL 3.0 core profile rendering context? If so, then those errors actually make sense, since those functions are not available any more.

Share this post

Link to post
Share on other sites

Shaders and generic attribute arrays is the only way to go. Check out the links in the Getting Started box on the forum page if you need some documentation covering the new API.

Share this post

Link to post
Share on other sites

So I've gone agead with the shaders, but it fails to compile and I'm not going to lie, the shader code has been checked to match identically to the tutorial, since there was an error I was thourah. The fragment shaders has no error and at no point returns any. If it means anything, the quad still draws to the screen without a texture.



ERROR: Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: "v" parse error
ERROR: error(#273) 1 compilation errors.  No code generated


const GLchar* vertexShader = ""
		"void main(void){"
		"	gl_TexCoord[0] = gl_MultiTexCoord0;"
		"	gl_Position = ftransform();"

	const GLchar* fragShader = " "
		"uniform sampler2D colorMap;"

		"void main (void)"
		"	gl_FragColor = texture2D(colorMap, gl_TexCoord[0].st);"

	static GLuint vertexID, fragID, shaderProgram;
	vertexID = glCreateShader(GL_VERTEX_SHADER);
	fragID = glCreateShader(GL_FRAGMENT_SHADER);

	GLint vertexSize = sizeof(*vertexShader);
	GLint fragSize = sizeof(*fragShader);

	glShaderSource(vertexID, 1, &vertexShader, &vertexSize); // Shaders length is defines by a NULL terminator
	glShaderSource(fragID, 1, &fragShader, &fragSize);


	static char* errorLog = new char[256];

	GLint status = glGetError();
	if(states.RENDERING_DEBUGGING && status != GL_NO_ERROR)
	glGetObjectParameterivARB(vertexID, GL_COMPILE_STATUS, &status);

		glGetShaderInfoLog(vertexID, 256, NULL, errorLog);

Share this post

Link to post
Share on other sites

I've solved the problem, my error was coming from the sizeof commands, as they would return the size of a char and not the string.

I used a null terminator to define the length of the shader, by adding \0 to the end of the shaders and replace the size with 0.

Now I have a black quad, somethings happening :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!