Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Aug 2012
Offline Last Active Oct 08 2015 01:58 PM

Topics I've Started

Handling an open world

01 October 2015 - 02:42 AM

Hi all,

In the last 2 years I learned a lot about 3D, OpenGL, GLSL, Rendering techniques like instanced rendering, framebuffers and post processing, but also things like ECS vs OOP, state managing, different Frameworks (GLFW, SDL, SFML, ...),
Physics (BulletPhysics) and stuff like that.
Previously I made little 2D games in Java and C++.

Now I'm feeling ready to dig deeper.
My current project is a 3D open world game. Graphics isn't relevant, that's why it will simply consist of low poly objects with low res textures and a pixelating post processing shader with a sci fi setting.
The first idea is a city, which feels a little bit like a living world.

Therefore my goals are cutted to
these points:
- animated neon lights and general lighting (banners, "advertises", street lamps, ambient lighting, etc.)
- walking pedestrians
- flying cars on multiple height levels
- moving around in first person

I think, I can definitely achieve this in a few years with my current knowledge. But there is one simple point I can't wrap my head around it:

- How are multiple (hundreds of) objects (buildings) handled? I know how I can render anything,but I didn't think, that I need to render anything at the same time. But how I can easily achieve it, to determine if something should be rendered and something not? How can I calculate if it is visible at the current position and view direction of the player?
And that, without hitting the performance a lot?

My ideas:
I know about texture streaming but is sonething like that possible for whole game objects? Like "game object streaming"?

I read stuff about so called SceneGraphs. But I don't really get it how it can help me? When each objects position is stored relatively to its parent position, in which way it would be simplier/faster to determine, if its in the viewport or not?

I hope it is understandable what I mean. :)

Please don't answer, if you just want to tell me something like "GTA V has over 1000 members in over 3 years full time". I appreciate it.

Issues with BulletPhysics & OpenGL

02 February 2015 - 01:40 PM

Dear community,

I'm currently programming a 3D game in pure C++ with OpenGL, GLM, ASSIMP, SFML & BulletPhysics. smile.png

But now, I'm at a point, where I'm done with it, 'cause I couldn't get the problem or find something on the internet, which can lead into the direction of a fix. huh.png 
I've got a problem with updating my meshs model matrix with the world matrix, getting from the btMotionState of a btRigidBody, to render it via shader. unsure.png


The shader computes the vertex location like

gl_Position = projection_mat4 * view_mat4 * model_mat4 * vec4(position, 1.0);

Where projection is computed by glm::perspective(...), view by glm::lookAt(...) and model by the physics system, see below. smile.png



So far, I'm creating the whole physics world in a class called "PhysicsManager".
It's a test and so it creates the whole bullet physics system like that:

m_broadphase = new btDbvtBroadphase();
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);


m_solver = new btSequentialImpulseConstraintSolver();
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0.0f, -9.81f, 0.0f));

// Floor
m_groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
m_groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, -1)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, m_groundMotionState, m_groundShape, btVector3(0, 0, 0));
m_groundRigidBody = new btRigidBody(groundRigidBodyCI);


// Model as a sphere in BulletPhysics
m_fallShape = new btSphereShape(1);
m_fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(8, 50, 8)));
btScalar mass = 2;
btVector3 fallInertia(0, 0, 0);
m_fallShape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, m_fallMotionState, m_fallShape, fallInertia);
m_fallRigidBody = new btRigidBody(fallRigidBodyCI);


// GLDebugDrawer from the demos of the Bullet 3.X github page
glDebugDrawer = GLDebugDrawer();
glDebugDrawer.setDebugMode(btIDebugDraw::DBG_DrawAabb | btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawConstraints | btIDebugDraw::DBG_DrawConstraintLimits | btIDebugDraw::DBG_DrawNormals);

And I'm updating the world each frame with 

m_dynamicsWorld->stepSimulation(1.0f / 60.0f, 10);

After that, I'm updating the meshs model matrix with

btTransform trans;

where "m_model" is a glm::mat4 initialised as "m_model = glm::mat4()". smile.png



Then rendering is done via

glBindTexture(GL_TEXTURE_2D, mesh->tex);

GLuint uniform_model = glGetUniformLocation(p_shader, "model");

glUniformMatrix4fv(uniform_model, 1, GL_FALSE, glm::value_ptr(p_objects->at(i).m_model));
glDrawArrays(GL_TRIANGLES, 0, mesh->size);

glBindTexture(GL_TEXTURE_2D, 0);

So I bind all the stuff of the 3D mesh, draw it and unbind it.



Problem is:

Why is my rendering not aligned with the physically computed bounding boxes?
(I mean not perfectly aligned like origin/center of mass but not anywhere near the collision box?)

Can anyone give me a hint or something like that?


Here's a picture of what I mean:





Help with calculate skinned models loaded with Assimp

30 September 2014 - 01:36 PM

Hey dudes.


I'm using C++ with SFML + OpenGL (+ GLM) + Assimp and I'm currently working on an animation system for my first 3D game project and I'm struggling with bone animated 3D meshs and the Assimp library since a few weeks.

Since threads to this theme are rare on the internet, I decided to ask you guys. ^^

First of all, I wanted to say, that I can load and display static models with textures assigned properly. smile.png 
Although the shaders for rendering to a different framebuffer and for post processing are working fine.
But I can't get some animation working flawlessly due to the fact, that I didn't understand some things in order to complete this task. ohmy.png

So, my main question is (which is moreover the main problem): How do I get one specific keyframe of the bones and get their transformations/rotations/scaling ?

My thoughts are:

  1. Load the vertex bone data, so each vertex know, by what bone it is how much influenced (done! biggrin.png )
  2. Each frame:
    - Get the time, since the animation started (done! smile.png)
    - Look up the "nearest" time stamp in the keyframe list (I didn't want to interpolate yet, just keyframe after keyframe for now )
    - Calculate all transformations per bone for this specific keyframe in a 4x4 matrix
    - Update transformation matrices in the shader (maybe done, can't test it... biggrin.png)

1. is done properly and I stuck with 2. since a few weeks now.
The problem is, so far I can define it, how can I look up one keyframe for each bone in Assimps "aiScene" and how do I calculate the per bone transformations? unsure.png 

Does anybody have good tips on this or something like that? blink.png 

Good evening,

Perlin Noise gives too small values?

04 August 2014 - 03:12 PM



Today I've implemented a perlin noise algorithm with extra methods like pertubation and eroding to create a terrain. smile.png

I found the code for it here: Click me smile.png


After the "addPerlinNoise()" method, you can see 3 reference pictures on that page (in the middle), build with the frequencies 1.0f, 4.0f and 1.0f + 8.0f (without perturb or sth like that, just plain noise).


If I use a frequency of 4.0f, this is my output (plain noise): https://imgur.com/7OElD3n


And when I use 64.0f as my frequency, I get this: https://imgur.com/dqA04N6


Can you help me to achieve something like the reference pictures with the reference frequencies (1.0f, 4.0f, 1.0f + 8.0f)?

I only understand a little behind the maths of it, so I can't really do something to fix it. sad.png


The code on the linked site is in C#, mine is in C++.


The only things, which are different between my code and the code on the site is the following part:

void PerlinGenerator::initGradients()
	//Type of random number distribution
	std::uniform_real_distribution<float> dist(0.0f, 1.0f);  //(min, max)

	//Mersenne Twister: Good quality random number generator
	std::mt19937 rng;
	//Initialize with non-deterministic seeds

	for (int i = 0; i < gradientTableSize; i++)
		float z = 1.0f - 2.0f * dist(rng);
		float r = (float)sqrt(1.0f - z * z);
		float theta = 2 * (float)M_PI * dist(rng);
		gradients[i * 3] = r * cos(theta);
		gradients[i * 3 + 1] = r * sin(theta);
		gradients[i * 3 + 2] = z;

Can it be the random double, which is used for the computing?


For the rendering I determine the vertex coordinates for a VBO like this and render it with glDrawElements(...) :

void Terrain::createVBO()
	// Create vertex data
	float *vertices = new float[3 * heightMap->size * heightMap->size];
	float blockSize = 16.0f;
	int vertex = 0;

	for (int y = 0; y < heightMap->size; y++) {
		for (int x = 0; x < heightMap->size; x++) {
			vertices[vertex++] = x * blockSize;
			vertices[vertex++] = y * blockSize;
			vertices[vertex++] = heightMap->heights[y][x] * blockSize;

	// Create index data

	// Create VAO

	// Create VBO

	// Create EBO

	// Handle vertex attributes in shader prog

Hopefully you can help me, thanks,


glAlphaFunc in gl20 ? or How do I enable alpha in gl20 ?

04 November 2012 - 03:23 PM

Hey guys.

I'm currently coding a little game with the libGdx library and I wanted to have a slight fade in/fade out effect if the screen changes (e.g. from MainMenu into the game).
After some time, I've got the idea, that I draw a black filled rectangle over the whole screen with an increasing alpha value. At the point where the alpha value is 0.0f (so, the whole screen is black) I change the screen to my game, where at this point my alpha value is getting bigger (so it will be transparent more and more).

So I implemented something like this:

// init
Gdx.gl.glEnable( GL10.GL_ALPHA_TEST );
// [...]
// render
Gdx.gl10.glAlphaFunc( GL10.GL_GREATER, 0 );
// render my quad

While having my project setting up with LwjglApplicationConfig.useGL20 = false; it will work very well.
But enabling gl20, it won't start, saying that there is a problem with GL10.GL_ALPHA_TEST
So I searched if gl20 have something like that... but now it's 30 minutes later and I don't have any solution.

Could you help?
What I have to enable in gl20 ( and setting up) to use alpha like in gl10 ?