Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Oct 2005
Offline Last Active Sep 28 2016 11:06 AM

#5240457 Help me to clear up my confusion about OpenGL

Posted by on 15 July 2015 - 04:38 AM

What are the libraries I need to achive goals 1 + 2? And can someone point me to a tutorial where loading and using shaders is explained well. Please no NeHe, I am getting confused by those tutorials.

You do not need any of those libraries. Nonetheless, they may make your life easier.


GLUT, FreeGLUT, and GLFW are libraries that abstract away the part where OpenGL touches the operation system. This part is not a component of OpenGL itself. If you deal with pixel formats, window handles, and input events directly in terms of your OS of choice, then you do not need them. Such libraries are neat in case that you want to go cross platform. IMO from those three you should go with GLFW (AFAIK GLUT is obsolete anyway).


Another library is GLEW that supports you in working with OpenGL extensions. This library is not necessary for the first steps (EDIT: Seems that for Windows this library is usefulin any case /EDIT). It is mostly meaningful in case that you want to write programs that should run on many platforms where some functionality may or may not be available from extensions instead of the core of OpenGL.


Another library is glm with provides vector and matrix math for OpenGL. It is obviously useful because with the go away of the matrix stack you need to do the math yourself.


What about Vulkan? Is it worth learning OpenGL right now? When is Vulkan coming out? Will it differ much from OpenGL? I read that it will be even more low level than OpenGL? Or would it be smarter to wait for it instead of deep diving into OpenGL right now?

There is an evolution from OpenGL 2.x over 3.x and 4.x up to Vulkan: Things got more and more compacted and closer to how the hardware works. People who know this evolution will probably understand Vulkan quickly. But I assume that jumping from immediate mode to Vulkan is a bit difficult. I would suggest that you start with OpenGL 4.x especially if you want to start just now.


If I get it right OpenGL applications can be implemented in both C and C++, what should be my choice here? I have a feeling that most of the tutorials are in C++? What are the pros and cons here?

OpenGL for C/C++ is a C API, so both are possible. You can also use Java or any of the various other language bindings that exist. However, the libraries you may want to use can perhaps demand for a language, like glm is a C++ library. So I suggest to use C++ from this variety.

#5240048 Why is my constructor/Renderer class being called twice?

Posted by on 13 July 2015 - 04:54 AM

I'm thinking, maybe its a system bug

Although that's possible, it's also improbable. Experience shows that it is often a piece of the own software apart from the obvious places.


What does the debugger (or a manually requested stack trace) say?

#5240039 Making my model class Vertex Independent

Posted by on 13 July 2015 - 03:36 AM

As you can currently see, my model class is dependent on Vertex::Basic32 vertex. How would I go about making this class vertex independent without actually using inheritance and virtual functions?

The only occurrences of Vertex::Basic32 I've seen are in Model::LoadFromFile(…). The responsibility of the Model class (as it looks for me) is to group related graphics resources for the runtime. As such it should not be responsible for how the components come together (may be loaded from mass storage or generated dynamically). It should especially not be burdened to know about assimp. Instead it should have getters and setters for its components and perhaps some validation routines.


The task of loading model components should be external to Model, e.g. in a ModelLoader class. This one (or one of its derived classes) then knows how Model components are represented within assimp, and is able to do the conversion into the internal data format.


It would be okay for ModelLoader to have virtual functions, because loading is a relative slow process anyway so the one virtual call would not be noticed. Furthermore, loading happens very seldom.



BTW: Please avoid linking to temporary external file sources as long as the files are relatively small, but embed them with the source tags into the post. On one hand that lowers the barrier for us to look at your problem, and on the other hand it will not drive the thread needless because of the disappearance of the external files one day.

#5240018 Why is my constructor/Renderer class being called twice?

Posted by on 13 July 2015 - 12:51 AM

In such a case: Set a breakpoint and run the program in debug mode. When the debugger stops, then look at the object-id of "this" and at the call stack. When after continuing the debugger stops a second time, look again at the object-id and compare it with the one before, and again look at the call stack. Use the call stacks to realize which functions have caused the invocations.

#5239699 54x50 tiles map searching for neighbours - takes extremely long

Posted by on 11 July 2015 - 03:08 AM

1.) An hour seems me too long for that piece of software. Do you have measured it with or without all those cout invocations? Printing so many lines to the console typically eats much performance.


2.) Of which type is m_walkables? Is it necessary to iterate it as done? Using a naturally indexable container would roughly half the amount of visits.


3.) How is getCost(…) implemented?


4.) How much copying is done inside setNeighbours(…)?



Although not knowing the exact situation, it seems me that you use the wrong approach. An indexed storage of the tiles would make this problem be much more performant. Perhaps you could explain the situation, so we can find a suitable solution.

#5239441 free private SVN with biggest disk space?

Posted by on 10 July 2015 - 02:25 AM

[edit] as pointed out below this can be as expensive as renting a server/service -- A 250W PC * 0.15c/kWh * 24hrs * 30days = ~$27/month -- so check your utility rates and look into low-power PCs to use as the server

For comparison: I'm running an old Core2 Duo linux based server at 65W and a new i5 QNAP NAS at 50W (measured during idle but rotating HDDs), each one with 4 HDDs in RAID 1+0. When disks get parked during low access frequency times, the values drop accordingly.

#5239154 New take on Conversation in Video Games

Posted by on 09 July 2015 - 02:01 AM

Well, what you describe is not really new. But it is nice to see another soul that's thinking how to replace the simplistic dialog tree mechanics. So don't get me wrong because most of the following sounds like critique. smile.png


a) There are more dialog mechanics besides the both you mentioned. The group of "branching dialogs" consists of the dialog tree but also of the "hub and spoke" variant; there are even planner like mechanics. See e.g. this and this article on Gamasutra.


b) A FSM is by definition a collection of states with conditional directed transition in-between. In an FSM just 1 state is active (as long as you do not mean HFSM). Implementing an FSM with those 6 degrees of freedom would practically become impossible very fast. What you describe seems me to be something different, more like some kind of decision tree. 


c) A "state" you've forgotten is the need / goal of the speaker. This is very important, because a person is willing to ignore mood and whatnot in case that it helps to yield a goal. It must even be possible to lie. All this may be important to drive the story, too.


d) Having the possibility to change the topic is nice not only for the player but also for the NPC, because it allows an NPC to drive the dialog into a direction that matches the story. But care must be taken that an NPC does not rapidly hop from one topic to another. When the player des so then the the opponent should probably get angry (i.e. changing its mood). See e.g. Emily Short's articles about that problem. (BTW: Emily has many interesting stuff to say, although she's more related with IF instead of video games.)


e) Besides the mechanics, also the UI plays a big role. The player need to recognize whether a sentence may endear or insult the opponent. Remember that not all players may understand the language in which they are playing good enough to recognize nuances. It is also nicer for the player not to need reading 4 times 5 lines of text just to decide which answer to give. There is an article about dialog UIs on Gamasutra (unfortunately I do not find it ATM). The more influence a dialog system has, the more important is its flawless controlling.


f) Regarding the effect of stats on dialogs and the possibility to change stats due to dialog, you may want to read the PDF about SimDialog available here.

#5238941 checking if resource has changed

Posted by on 08 July 2015 - 03:40 AM

The OP asks for "dirty resources to be saved or discarded" and a belonging user decision. This is a different problem than those of hot swapping of updated resources. The former one means to update files from memory, and the latter means to update memory from files.


In my engine code I check if resources* have changed so I can ask the user if they want to save or discard the changes in various places. [...]

I'm not sure why this happens "in my engine", assuming that "engine" means a game engine in the meaning of a game runtime. Resource changes and save requests belong to the editor. Integration of the editor with the game runtime like in "editor in game" is IMO not a clean way since it burdens the runtime code and hence makes it maintenance more difficult.


[…] but before I dive in and change a bunch of stuff I though I would ask others how they handle the "dirty" problem.


Some possibilities and thoughts:


Command style editing


Resource changes and save requests belong to the editor. Making changes undone should also be possible in such an environment. Instead of using a single flag, a counter of dos / redos (increments) and undos (decrements) targeting the respective resource can be used to track dirtiness. A saving would reset the counter to 0, and any value different from 0 (notice that this includes negative values, possible due to undos after a saving) denotes dirtiness.


This way does not counteract issue #2 as mentioned in the OP, but using OOP style patterns like the Command may support to avoid that kind of bug.


It also does not totally counteract issue #1, since changes back to a previous state are only considered if performed as an undo. However you need to notice that some kinds of change-back (like translation when using floating point numbers) may yield in a visually identical resource although also the message digest of its serializations will differs.



What You Made Is What You Want (perhaps somewhat controversial)


Notice that from a users point of view (and ignore the fact that we, as users, are familiar with the concept of saving, because this is just due to history) the dual state of a software object, namely its state as file and its state in memory, is a suffering. The whole load/save stuff exists due to technological reasons only, not because it is the optimal workflow. Ideally you could stop working with a software, and when continuing it the state is as you left it before. This obviously must include the possibility to roll back to previous states. However, the consequence is that nothing like a dirty state exists anymore; at any moment the current state is assumed to be what the user wants.



Message digests


When checking the message digest of the in-memory representation with what is stored in a file, it would obviously be killing the performance if every digest is computed on the fly. Instead, if possible, the digests of files should be computed once and stored along the file. This may even be done in a kind of catalog file that's used to collect the names and digests of all files in a directory that are used in the project (similar to archives). 

#5238628 Why use texture splatting?

Posted by on 06 July 2015 - 10:09 AM

Is there something I am missing?

The RGB textures are of fine detail, repeating many times over the terrain. The blend texture(s) are coarser, covering a large area of the terrain. I.e. you do not have blend control over each individual pixel but the splats.

#5237458 Memory management patterns in C++

Posted by on 29 June 2015 - 04:18 AM

I don't think it is possible in modern games to just have a single memory management scheme. You need multiple and use each in the right way.

Seconded. Hence ...


How have you solved this problem in your projects?

… situation dependent. Here are some examples that do not rely on reference counting:


Regarding the ownership, resources are owned by the respective resource management systems, while game object components are owned by the respective component service systems. Scratch memory is owned, of course, by the instance that works with it. Sometimes there is a clear hierarchy; e.g. network messages are owned by a transaction, which themselves are owned by a connection. And so on.


Regarding lifetime, resources are typically bound to the lifetime of higher concepts. E.g. resources for the GUI or the player avatar are bound to the lifetime of the game itself, while other resources may be bound to the lifetime of the level or a region. Game objects are created / destroyed at a defined step in the game loop. Each component service system is responsible to deal with destroying game object components of the managed types and in a way that is suitable for the service system. Network messages are recycled in the well known pool memory allocation scheme.


Addressing game object components across service systems is based on handles instead of pointers, but handles can be resolved to pointers when necessary. Such pointers are guaranteed to be valid only for a single run through the game loop. Resources are addressed similarly.

#5237246 A more simplistic way for this?

Posted by on 28 June 2015 - 06:45 AM

Im just wondering what sort of trig formula is this
dx /= c;
dy /= c;

change of x = change of x/ hypotenuse?

Together with the computation of c it is a standard operation in vector algebra called "normalization", in this case using the so-called Euclidean norm or 2-norm. The Euclidean norm of a vector denotes the length of the vector in Euclidean space. Then dividing the difference vector (which is given by the 2 differences as (dx dy) ) by its own length results in a vector that points in the same direction as the original vector but has a length of 1 (i.e. it has unit length); thus it is called "normalization". Hence the resulting endpoint lies somewhere on the unit circle, i.e. the circle with radius 1. So the normalization step is equivalent to

   dx := cos( angle ) = r * cos( a ) where r==1

   dy := sin( angle ) = r * sin( a ) where r==1

but where the angle a is anything in [0,2pi] (as opposed of what you compute as angle in the OP).

#5237229 A more simplistic way for this?

Posted by on 28 June 2015 - 04:06 AM

Im just wondering if you guys implement the same functionality with minimal ifs. and if so how did you do it?


1.) The if clauses are not complete, because none of the conditions checks for dx==0 or dy==0. However probable such a case is, it does cost nothing to check it but will fail if not doing so.


2.) All the if clauses would not be needed if the atan2 function would be used. As you already have noticed, there is a meaning with the atan2 function that makes it superior (in many cases) compared to the atan function.


3.) The entire approach can be replaced by using vector math. If I understand the code snippet correctly then something along

                // elements of difference vector
                dx = mousex - sprite.originalPosition.X;
                dy = mousey - sprite.originalPosition.Y;

                // length of difference vector
                c = (float)Math.Sqrt(dx*dx + dy*dy);
                if (c > radius)
                        // direction vector (normalized difference vector)
                        dx /= c;
                        dy /= c;

                        // adding scaled direction vector to position
                        mousex = (float)sprite.originalPosition.X + (radius * dx);
                        mousey = (float)sprite.originalPosition.Y + (radius * dy);

should do the same thing. (Notice that the above solution assumes that dx, dy, and c are floating point variables.)



BTW: I'm missing what exactly this has to do with a joystick...

#5236926 -std=c++11 with Xcode 4.6

Posted by on 26 June 2015 - 08:51 AM

Not sure whether Xcode 4.6 already supports C++11; you should consider to switch to a 5.x version.


However, when you open the "Build Settings" for a target, then search for the fields "C++ Language Dialect" and then "C++ Standard Library" and pick the C++11 option that suit your needs. If the options do not provide some "C++11" and/or "GNU++11" stuff, then you need to upgrade Xcode, of course.

#5236885 Dealing with different collision responses in an entity-component system

Posted by on 26 June 2015 - 01:45 AM

When I once thought about collision in ECS I saw several problems when selecting a collision response: (1) An entity may have more than a single collision volume, (2) the response depends on the types of both participants, and (3) simultaneous collisions involving the same entity have to be handled / resolved in a meaningful manner.


For example, in an RPG with a sense system, we want to support damage of course, but perhaps distinguishing different body parts so that the collision volumes for this are more detailed than the "physical" one used to avoid running into a wall. The sense system may introduce different collision volumes for the visual, aural, and olfactory senses, and that for both roles as detector and as stimulus.


Well, the conclusion to me was that I moved away from a unified collision system and towards dedicated systems. To serve this, there is also no longer a single unified collision component but components that match the systems, of course. The collision volumes are then parameters to that components, and the components declare the owning entity to participate of the respective systems and also in which role this happens. While all such systems use the same volume intersection services, each one manages the own set of colliders and each one has its own set of rules of how to respond to a detected collision.

#5236402 manging lifetime of textures/buffers etc

Posted by on 23 June 2015 - 12:48 PM

I would have to somehow know that nothing is using a particual Texture any more and manually call mDevice->DeleteTexture(textureHandle).
So do people implement some form of reference counting inside the Device to count CreateTexure and DeleteTexture on each texture handle? It seems if I'm going to do that I might as well just use a shared_ptr anyway to count it?

Many engines manage memory not in a totally dynamic way. Instead they define memory budgets for particular purposes and they define lifetimes a priory. For example, some assets are loaded at game start and unloaded when the game ends, i.e. they have game lifetime. Level based or region based lifetime are other popular methods. Streaming may also be used in which case buckets of memory are allocated once and then cleared and re-used in dependence on vicinity or whatever. However, the clue is that the lifetime is not measured but prescribed.


I do not know what exactly the Molecule Engine does, but the articles and comments in that blog mention such things, too.