Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Dec 2001
Offline Last Active Feb 10 2015 09:02 PM

#5204071 Basic OpenGL State Machine Questions

Posted by on 13 January 2015 - 05:24 PM



I can't seem to find this information on the OpenGL online documentation and it's been bugging me for a while. The gist of the question is "how/when is state saved".


For instance let's consider this fairly standard VBO initialization:

GLuint vaoID, vboID;

glGenVertexArrays(1, &vaoID); // Create our Vertex Array Object

glGenBuffers(1, &vboID); // Generate our Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), &vertices.front(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Set up our vertex attributes pointer

and Render hook (assume indexCount is initialize properly when the mesh is loaded and there is an associated index buffer object, yada yada)

glBindVertexArray( renderInfo.vbos.vaoID );
glDrawElements(GL_TRIANGLES, renderInfo.indexCount, GL_UNSIGNED_INT, (GLvoid*)0);
glBindVertexArray( 0 ); 

So this creates a Vertex Array Object with an associated Vertex Buffer Object that holds my vertex data. This works and I'm happy.


My question is, what if I want to change the data that is passed in the Vertex Buffer at runtime (say maybe I have several lists of vertices that are pre-transformed to specific animation keyframe positions or something; I'm not doing that but it's an example that's easily digestible). Can I do that? How do I do that? Is the state set in glVertexAttribPointer in the above invocation somehow "saved" to the vertex array object?


Would the "re-binding" look something like the following (assuming that vboID_2 is created just like vboID but with different data)


//does this work as re-binding??
glBindBuffer(GL_ARRAY_BUFFER, vboID_2);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

glDrawElements(GL_TRIANGLES, renderInfo.indexCount, GL_UNSIGNED_INT, (GLvoid*)0);
glBindVertexArray( 0 );

Hopefully this question is clear, if long-winded. Let me know if I need to clarify anything...



#5202858 OpenGL 4 Shadow Map Problem

Posted by on 08 January 2015 - 10:21 AM

PS, Wired:





is iuseless since you are not using hardware extension for comparsion but shader.


Are you sure this is correct? The openGL 4 documentation of glTexParameter and also the documentation of the GLSL texture(...) calls both suggest this is necessary for texture(...) to be able to make the depth check correctly from a sampler2dshadow





Granted that tutorial is quite old, so I could just be wrong here smile.png

#5160918 Problem with glDrawElementsInstanced and glVertexAttribDivisor

Posted by on 16 June 2014 - 02:26 PM

ok, well, found the answer.


If you are using glVertexAttribPointer, the data will be converted to a floating point value. For passing unsigned data without information loss, like I'm trying to do, you should use glVertexAttribIPointer. I'm not totally sure why there would be data loss since I would have imagined that it would be a (uint32_t)((float)originalValue) kind of thing, but there you have it. Data is getting into the shader. Happy times!

#4892021 Which Country Should I Move To?

Posted by on 08 December 2011 - 07:44 PM

Well, I don't know what the work visa rules are for other countries but that's going to be your biggest hurdle. For the US, foreigners cannot get a work visa to move here unless they have at least ~6 years prior professional experience in the field of the job to which they are being hired (I forget what the exact number is). It is likely that other countries have similar rules for granting work visas. So if you really want to move, your best plan might be:

- see who can hire you
- move there

Having English as a restriction would also be unnecessarily limiting your options. Countries that speak English at work would be: US, Canada, Britain, Australia, and those below :). That's it. And if you're moving to Quebec, Canada you probably want to learn French if you want to get along more easily with the locals.

Mostly your best bet of working internationally is to get a job with a multi-national company in the US and then transfer internally to a foreign office. Getting hired out of country, especially without work experience is extremely challenging.


#4876833 Some newbie questions about AI

Posted by on 25 October 2011 - 11:16 AM

Ehh... it's not a matter of being too expensive, so much as there being more efficient ways to accomplish the same results with less resources and often better fidelity in the end product.

Yeah. Of course it depends on the game but the biggest reason that we don't use any of those solutions is that they aren't "directable": in the sense of directing actors. Most single-player action games require hand tuned encounters with the AI doing very specific things at very specific moments or at least being able to be directed by the level designers to achieve a certain effect. Most of the more complicated "real AI" algorithms are meant to be emergently intelligent and/or act more like an actual human. While that may be fun in multiplayer, it's often not fun at all in single-player. Single-Player AI tends to be more about smoke and mirrors and the illusion of intelligence; think of most game AI as a foil for the player mechanics, not as some kind of artificial human.

A friend of mine said it the best "the role of single-player AI is to die convincingly".


#4859977 Can someone explain projection matrices?

Posted by on 10 September 2011 - 07:25 AM

Honestly, it sounds like you just need to sit down and learn Linear Algebra.

Matrix multiplication is just a mathematical mechanism like normal addition or multiplication or division. You just have to learn how to perform it.

Linear Algebra tutorial. I don't know if this tutorial is any good but it was the first hit on google:

Matrix Multiplication

Projection Matrix construction


#4853343 Interview

Posted by on 24 August 2011 - 01:23 PM

Ask the HR representative that's setting up the interview for you. This is a normal question to ask, and I've asked it before every interview. Different offices have different dress codes and expectations for interview candidates.


#4813254 If/Else Statements in Swtich Statements?

Posted by on 19 May 2011 - 06:26 PM

Just add parens to the case block to scope things properly

    case 0:
        if (blah blah)


#4800104 How does ai spot enemies

Posted by on 18 April 2011 - 06:14 PM

Raycasting is how we do it.

If you're unsure what raycasting is, it's basically a collision detection routine. You project a ray (line segment) into your physics world. You then collect every object that this ray intersects. You ignore the insitgator object (you don't want the trace hitting the AI doing the trace). So basically it's a series of "does this line intersect this collision geometry" checks. A good physics system optimizes this with spatial partitioning trees or whatever so you don't check the line against every object in the scene.

It is, as you might imagine, a very expensive operation. So you want to make sure you aren't evaluating LOS every frame. You'll have to play with the numbers for your actual game but in practice I find that AI doesn't really need to raytrace to it's targets more than 1-2 times a second. Generally visibility is stored in a "VisibilityManager" or some other meta object that does X number of raytraces per second and caches the results for the AI to look up whenever it needs to.

For more advanced behavior you want to make the AI remember the last place where it saw the target. That way, when LOS starts failing you have a position from which the AI can start some kind of search behavior.


#4800088 How does ai spot enemies

Posted by on 18 April 2011 - 05:15 PM

Do a line of sight check: raycast generally through your physics system. If it doesn't hit anything between the AI and the target, then the AI has potential line of sight. You can constrain that with cheaper tests like a vision cone, a sight radius, etc.

Modern games can often incorporate other modeled senses like sound. You have obejcts that make sound which is modeled by a radius. Any AI within that radius will become aware of the sound maker. You can also have a few different vision cones (a long narrow far vision and a wide short near vision). Depending on other game mechanics it's also sometimes helpful to have a short-range proximity sense: i.e. if you're closer than a few meters to an AI, even if they can't "see" you then they will become aware of your position after a brief delay.


#4799030 Thumbs up, bro!

Posted by on 15 April 2011 - 10:47 PM

Though I doubt you'd share, I'd be super curious to know what traffic has been like since the layout change. It seems to me like the forums have become a fairly useless wasteland. That and the original articles are the only reason I ever came to this site (for what, maybe 6 years now...). Hacker News, Reddit, Kotaku, gamasutra and my RSS feed are WAY better sources of industry news or "one stop shopping" than gamedev ever was or currently is in. But you guys got probably 80% of my day's worth of web traffic. Now you get maybe 5%

IMO, if you're focusing on news I think you've totally misunderstood what makes this site worthwhile.

I think that without the forums, this site dies. Outside of my workplace, there has never been another resource that I could find that has been filled with such experts in this field as gamedev has been. It will suck if that continues to fade away.

Totally unrelated: it's been strange to me how much the loss of my old user score from the old rating system has disincentivized me from coming back. I'd guess I'd always used that as some kind of self-worth to the community... w/e

Please fix the forums... (recent threads up above the fold on the homepage so I can just hit F5 while I'm at work without necessarily being logged in)

In the new botique web era, niche wins, same-same catchall loses.


#4767832 What's Next?

Posted by on 31 January 2011 - 11:59 PM

Maybe this question might help me out a little better, what would a game like Farmville consist of, as far as the number of team members, time, financial, etc. aspect of it?

Here's an interview with the Project Lead from Farmville. The short: 10 people (core team), 6 months and $40 million dollars

High price would likely be for the Amazon Cloud space to deal with all their bandwidth and putting in the whole micro-transaction infrastructure. But the article might go into that.

Bottom line: making games is expensive. The typical pricetag for a AAA quality game is between 30-100 million. Outliers like Red Dead Redemption are in the multiple hundreds of millions to develop. Super outliers like World of Warcraft cost ungodly amounts of money :)


#4764803 Any reason to NOT use STL?

Posted by on 25 January 2011 - 06:42 PM

The common argument against STL is generally about memory fragmentation or "un-necessary features". However, it's mostly a religious argument. You can override the memory allocators to use your own deal if you want. Most anti-STL people have been around for a while and remember the terrible old days when Microsoft's STL implementation was pretty crappy. But it comes down to control. If you aren't already intimately familiar with how the STL algorithms are implemented, then you may like to roll your own so you know *exactly* what to expect. On some projects I've used STL, on others it's been prohibited.


#4762123 Proof God doesn't exist?

Posted by on 20 January 2011 - 06:02 PM

Different religions have different answers to this.

In the Greek mythology, many of the gods did in fact have parents: Athena was born out of the head of Zeus. Zeus in turn was created by Uranus who was birthed from Gaia who was born of Chaos and Chaos existed eternally before that: nothing created Chaos, it was timeless.

In the Christian religion the tree is a lot simpler. Jesus was the son of God. After he died they became part of the trinity: became again one god. But the god of the old testament is timeless (similar to Grecian Chaos). That is he existed forever. "Without beginning and without end" or something like that, I think, appears in the bible, or various hymns or both... I don't remember explicitly.

From a physics standpoint things are perhaps even simpler. Time simply did not exist before our universe came into existence. In so far as I understand current physical theory, time is actually a product of the Big Bang. So to talk about "time before the Big Bang" is actually meaningless.

But speaking purely philosophically, no you really haven't found "proof of God's non existence". That particular philosophical point has been successfully quashed probably a few hundred or even thousand years ago with the argument of the eternal nature of Gods. The idea that something must have a beginning is a strong human intuition but is not necessarily a fact in either a philosophical or scientific way. If you can conceive of something lasting from now until "forever" you should also be able to imagine something that has always existed. Both directions are equally infinite :)


#4761001 C++ general questions

Posted by on 18 January 2011 - 07:59 PM

-What is a game engine? I know people say "game engine" and use the word all the time, but what IS it? Is it the entire game itself? or is it a "logic" applicator? or... can somebody clarify that for me? (no links please :/)

It's the part of your game that you strip out to use in your next game. Don't worry about it until you finish a game

-In your opinions, Visual Studio 2010 or Dev-c++? I heard the latter is in bad shape anymore, but i also hear people still recommending it

Dec-c++ is over 10 years old and terrible. Visual Studio is pretty much the industry standard and a really awesome IDE. You can get it free, just google "Visual Studio Express Edition"