• 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
SeraphLance

Trouble with IBOs

6 posts in this topic

So I'm trying to run an extremely barebones OpenTK program -- basically the quickstart program (which worked), but with VBOs/IBOs instead of immediate mode.

 

I generate a grid of vertices, and associated indices.  For testing purposes, that grid is currently statically set to just a 2x2 quad, and the vertices/indices check out when I debug it.  If I draw the vertex buffer with GL.DrawArrays, it also works, albeit with some massaging to get it to look right.  However, the moment I try to call GL.DrawElements, the entire program crashes, with the worst driver error I have ever seen:

 

"Too many errors occurred, which indicates a serious problem from which we cannot recover.  The application must close."

 

NVIDIAs site help doesn't really target developers, so none of the information is very helpful to me.  Plus, I'm fairly sure my drivers shouldn't have a problem with IBOs no matter how old they are (and I updated them just in case).  So, I'm pretty sure despite the contents of the error and the literature on it, it's a problem with the program.  I can't seem to figure out what though, since the problem is stupid simple.

 

Code is below:

 

http://pastebin.com/RUTBk0LS

 

I'd appreciate if anyone could see if I'm missing anything.

 

EDIT:  After about 3 hours, I've figured something out.  Not sure why it's correct, but it is:

 

//GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, indices);
//should be
GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, (IntPtr)(0));
Edited by SeraphLance
0

Share this post


Link to post
Share on other sites

Ok, so I've got a new issue, and since this still technically relates to index buffers I'm going to post it here.

 

I'm trying to write a tile engine.  Each tile therefore needs to have it's own texture.  However, I don't want to render every single tile in it's own draw call either.  As I understand it, the typical way to do this is texture atlasing, and, as I further understand it, this is done by varying the texture coordinates on the vertices.  That makes sense when I have duplicate vertices.  However, how does that work when I index them?  A vertex can only have one texture coordinate, obviously.  For example, if I have a 2x2 texture atlas, let's say with rock/dirt/cobblestone/grass tiles, and a 2x2 map.

 

Atlas
+-------+-------+
|	|	|
|Rock	|Grass	|
|	|	|
+-------+-------+
|	|	|
|Dirt	|Stone	|
|	|	|
+-------+-------+


Map
+-------+-------+
|	|	|
|Grass  |Grass	|
|	|	|
+-------+-------+
|	|	|
|Grass	|Stone	|
|	|	|
+-------+-------+

 

In this case, what would be the texcoord of the middle vertex on the map?  To match the bottom left tile, it would need to be (1, 1), but to match the bottom right tile, it would need to be (0.5, 0.5).  How is this resolved?  Do people just forget about indices and duplicate the vertices?  Or am I fundamentally misunderstanding something about texture atlasing?

0

Share this post


Link to post
Share on other sites

This is addressing your first post.

 

 

EDIT: After about 3 hours, I've figured something out. Not sure why it's correct, but it is:



//GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, indices);
//should be
GL.DrawElements(BeginMode.Triangles, indices.Length, DrawElementsType.UnsignedShort, (IntPtr)(0));

 

 

That's because the fourth element should be an offset into the "enabled" array(s) of elements.  From the OpenGL docs:

 

 

void glDrawElements(GLenum  mode,  GLsizei  count,  GLenum  type,  const GLvoid *  indices);

 

When glDrawElements is called, it uses count sequential elements from an
            enabled array, starting at indices to construct a sequence of
            geometric primitives.

 

 

I'm going to hazard a guess that there's a helper function in OpenTK that takes an array argument and converts it to an IntPtr type.  Your working version essentially states "start drawing the enabled elements, and don't skip anything"

Edited by BCullis
1

Share this post


Link to post
Share on other sites
I'm going to hazard a guess that there's a helper function in OpenTK that takes an array argument and converts it to an IntPtr type.  Your working version essentially states "start drawing the enabled elements, and don't skip anything"

 

I see.  The OpenTK docs say something along the lines of

 

"indices Specifies a pointer to the location where the indices are stored."

 

As a result, I read my working version as "start drawing these indices at memory location 0" which frankly sounds ludicrous.  I think I get how it works after your explanation though, and vaguely recall something similar in the draw calls in XNA as well.

0

Share this post


Link to post
Share on other sites

Re: texture atlasing

 

What's your projected triangle count for the full set of rendered tiles?  I ask because the duplicate vertex solution would definitely work, but the memory savings via indexing is vastly different between a 200 poly grid, and a 200k poly grid.

0

Share this post


Link to post
Share on other sites

Hard to say at this point, to be honest.  It's just one of those things where I plan to massage with my dimensions until I get something that "works" for my project.

 

It's a pretty lightweight game, so even 200k polys would probably be easily in budget, but I'd like to do things as "right" as I can in this case since its such a modular piece of code.

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