Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


sunk

Member Since 02 Oct 2011
Offline Last Active Oct 05 2014 05:16 AM

Topics I've Started

Setting up a camera with SFML and raw opengl calls

30 September 2014 - 02:17 PM

Hi,
 
I'm having some trouble with using an sf::VIew as a camera when mixing raw opengl calls with SFML. For example, here in my code I'm mixing opengl calls with SFML: https://github.com/SundeepK/Clone/blob/wip/add_splittable_enviroment/src/Game.cpp#L58. Everything drawn by SFML is correct but the textures drawn manually using opengl calls follow the camera when the player moves, rather than staying put. Here's an example image: http://i.imgur.com/umME791.png?1 . When I move, you can see that the wooden texture follows rather than staying where it's box2d body is.
 
What would be the general way of handling a camera in this scenario? Would I need to write a custom camera class?

Opengl - How to texture polygons that may not be quads

29 June 2014 - 11:36 AM

Hi, I'm currently using Box2D, Opengl and SFML (still pretty new to this stuff) to build a splitting engine where the user can use their mouse to split shapes into smaller ones. I'm having a hard time actually figuring out how the split shapes would be textured after they have been sliced. For example, say I have a quad which has been textured correctly. I slice the square on the top right causing a new triangle and a 5 sided polygon to be created. How would the 2 new shapes be textured after this? I've only seen examples of quads and triangles being textured in opengl and subrecting a texture in SFML won't work since it only supports rects. Any thoughts? Thanks.


Fixed timestep with box2d and SFML

08 June 2014 - 09:22 AM

Hi, I've tried to implement a simple demo using box2d and SFML (a simple moving box). I've managed to implement a fixed timestep to the one described here http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d . The only problem is that moving my simple square around, it seems to become slightly  blurred and stretched. This maybe because its moving to fast (since it doesn't happen when moving slowly). I've ported this code to SDL as well and it seems to give similar results and I can't put my finger on why this is happening. I'm working on ubuntu but I've made a visual studios  project for windows as well showing the problem:

 

Linux (executable) https://www.dropbox.com/s/dzf4f8w6f6fl1o0/FixedTimeStepTest.rar

WIndows (visual studios project) https://www.dropbox.com/s/ghazj8tqyppk8v9/sfml%20test.zip

 

Should work, but let me know if you have issues (mostly likely need to have box2d and sfml install if your running on linux and running on windows you'll need to point to sfml directory for the include directories).

 

The actual implementation of the fixed timestep can be found below:

void B2DWorld::update(float dt, ActionController<std::string>& actionController){
    m_fixedTimestepAccumulator += dt;
    const int steps = floor(m_fixedTimestepAccumulator / FIXED_TIMESTEP);

    if (steps > 0)
	{
		m_fixedTimestepAccumulator -= steps * FIXED_TIMESTEP;
	}

	assertAccumilation();
    m_fixedTimestepAccumulatorRatio = m_fixedTimestepAccumulator / FIXED_TIMESTEP;

    const int clampedSteps = std::min(steps, MAX_STEPS);
	for (int i = 0; i < clampedSteps; ++ i)
	{
		resetStates();
		actionController.triggerCallbacks(m_fixedTimestepAccumulatorRatio);
		step(FIXED_TIMESTEP);
	}

	interpolateStates();
	m_world.DrawDebugData();

}

void B2DWorld::step(float dt){
    m_world.Step(dt, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
}

void B2DWorld::interpolateStates(){

	const float oneMinusRatio = 1.0f - m_fixedTimestepAccumulatorRatio;

	for (b2Body * b = m_world.GetBodyList (); b != NULL; b = b->GetNext ())
	{
		if (b->GetType () == b2_staticBody)
		{
			continue;
		}

		PhysicsComponent *c   = (PhysicsComponent*) b->GetUserData();
		c->smoothedPosition = m_fixedTimestepAccumulatorRatio * b->GetPosition () + oneMinusRatio * c->previousPosition;
		c->smoothedAngle = floor (m_fixedTimestepAccumulatorRatio * b->GetAngle () + oneMinusRatio * c->previousAngle);
	}

}

void B2DWorld::assertAccumilation(){
	assert (
		"Accumulator must have a value lesser than the fixed time step" &&
		m_fixedTimestepAccumulator < FIXED_TIMESTEP + FLT_EPSILON
	);
}

void B2DWorld::resetStates(){
for (b2Body * b = m_world.GetBodyList (); b != NULL; b = b->GetNext ())
	{
		if (b->GetType () == b2_staticBody)
		{
			continue;
		}
 		PhysicsComponent *c   = (PhysicsComponent*) b->GetUserData();
		c->smoothedPosition = c->previousPosition = b->GetPosition ();
		c->smoothedAngle = c->previousAngle = b->GetAngle ();
	}
}

The whole project is here: https://github.com/SundeepK/Clone/tree/wip/fix_time_step

 

After a bit of playing around, it looks like it maybe the way opengl renders things or the way its being setup. Any idea's on what maybe causing this issue? Thanks.


XNA Quadrender question

21 August 2012 - 12:31 PM

Hi, I have some basic questions about quadrender and how things are drawn on the screen, go easy on me, I'm new to XNA . Have a look at the below class:

internal sealed class QuadRender
    {
	    private VertexPositionTexture[] verts;
	    private GraphicsDevice myDevice;
	    private short[] ib = null;
	    ///
	    /// Loads the quad.
	    ///
	    ///
The engine.
	    public QuadRender(GraphicsDevice device)
	    {
		    myDevice = device;		 
		    verts = new VertexPositionTexture[]
					    {
						    new VertexPositionTexture(
							    new Vector3(0,0,0),
							    new Vector2(1,1)),
						    new VertexPositionTexture(
							    new Vector3(0,0,0),
							    new Vector2(0,1)),
						    new VertexPositionTexture(
							    new Vector3(0,0,0),
							    new Vector2(0,0)),
						    new VertexPositionTexture(
							    new Vector3(0,0,0),
							    new Vector2(1,0))
					    };
			 ib = new short[] { 0, 1, 2, 2, 3, 0 };
	    }			 
	    ///
	    /// Draws the fullscreen quad.
	    ///
	    ///
The effect.
	    public void RenderFullScreenQuad(Effect effect)
	    {
		    effect.CurrentTechnique.Passes[0].Apply();
		    RenderQuad(Vector2.One * -1, Vector2.One);
	    }
	    public void RenderQuad(Vector2 v1, Vector2 v2)
	    {		  
		    verts[0].Position.X = v2.X;
		    verts[0].Position.Y = v1.Y;
		    verts[1].Position.X = v1.X;
		    verts[1].Position.Y = v1.Y;
		    verts[2].Position.X = v1.X;
		    verts[2].Position.Y = v2.Y;
		    verts[3].Position.X = v2.X;
		    verts[3].Position.Y = v2.Y;
		    myDevice.DrawUserIndexedPrimitives
			    (PrimitiveType.TriangleList, verts, 0, 4, ib, 0, 2);
	    }
    }

What I'm confused about is the co-ordinate system, what I mean is why does (0,0) represent top left and (1,1) represent bottom right? For example if I have a 800x600 screen, bottom right would be (800, 600), so why is (1,1) used instead. Also why are all the vertices initialized with a Vector3(0,0,0). Whilst I'm here, whats the significance of the other methods present in the class and the ib array?

PARTNERS