Followers 0

Texturing a VBO

11 posts in this topic

! 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];

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTexture(GL_TEXTURE0);
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);

glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 0, 0);

glEnableVertexAttribArray(1);
glEnableVertexAttribArray(0);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glBindVertexArray(0);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);

GLenum error = glGetError();
if(states.RENDERING_DEBUGGING && error != GL_NO_ERROR)
logError((char*)glewGetErrorString(error));

return;

Thank you for any help

Edited by Joshhua5
0

Share on other sites

If you have an error, then you should also figure out which exact line is giving you that error.

0

Share on other sites

I did that at it came to glEnable(GL_TEXTURE_2D); giving the code 1280

0

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.

0

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
0

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.

2

Share on other sites

What do you use for post 3 then?

because right now I'm using OpenGL 4.1

Edited by Joshhua5
0

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.

2

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 char* errorLog = new char[256];

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

if(!status){
logError(errorLog);
}

0

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 :)

0

Share on other sites

Since vertexShader is a pointer to a char, *vertexShader is of type char, and thus sizeof(*vertexShader) is equivalent to sizeof(char). In order to use sizeof to get the length of the string, you have to make vertexShader an array, and take the size of the array. I also recommend you insert new-line characters at each new line so that you can get some sensible line numbers from the error messages.

const char vertexShader[] = ""
"void main(void){\n"
"    gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"    gl_Position = ftransform();\n"
"}\n";


2

Share on other sites

I'm still having issues drawing a simple texture to the screen :(, now nothing will apear and the drawArrays now returns a 1282 which has stumped me. Instead of creating a new thread I thought I would revive this one. I wanted to make sure that all my functions are correct.

Here is the link to the whole function to keep the post size down. http://www.pastebucket.com/19567

Thank you for any help at all.

        unsigned int VertexBufferObject[1];
GLuint error = glGetError();
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex.textureID);

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

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);// Returns error 1282

glDisableVertexAttribArray(0);

glBindTexture(GL_TEXTURE_2D, 0);
glDeleteBuffers(1, VertexBufferObject);
glDisable(GL_TEXTURE_2D);

0

Create an account

Register a new account