• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
JoshuaWaring

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 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.

0

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
0

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.

2

Share this post


Link to post
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 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.

2

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

	glCompileShader(vertexID);
	glCompileShader(fragID);

	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){ 
		glGetShaderInfoLog(vertexID, 256, NULL, errorLog);
		logError(errorLog);
	}
0

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

0

Share this post


Link to post
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";
 
int vertexSize = sizeof(vertexShader);
2

Share this post


Link to post
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);

	// Pass texture to shader
	glUniform1i(glGetUniformLocation(shaderProgram, "colorMap"), GL_TEXTURE0);

	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

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  
Followers 0