Hi, I'm new to Box2D and I am currently trying to use Box2d with SDL so that i can load images, musics and stuffs.. But I can't get Box2D to link with the SDL library nor the header codes in the SDL include folder.. Anyone have any idea to link them?
SDL and Box2d
Build IssuesYou might give a little more information, such as compiler/IDE you're using for your project.d
Bill
Bill
o.. I am using Visual Studio 2005 and programming with C++ language and OpenGL
if you're programming in C++, trhere is no excuse to not use the SFMLwich is eaisier and faster 😉 😀
PS: i didn't understand youre problem 🙁 , explain more
PS: i didn't understand youre problem 🙁 , explain more
well when I built my SDLBOX engine I just basically made a new .cpp file which included the sdl and box2d libraries and went from there. Not really sure what your problem is or why you wouldn't want to do that. Here is a little example from a basic pong game i made.
I hope this helps.
Code:
#pragma once
#include <vector>
#include "Box2D.h"
#include "sdl.h"
//#include "sdl_ttf.h"
#include "Object.h"
#include "Player.h"
class box_sdl_engine
{
public:
static box_sdl_engine *instance;
//Functions==================
void renderScreen();
int getPlayers(void);
void showScore(bool*);
int RunGame(int);
bool announceWinner(int);
int InitGame();
void EndGame(void);
int getAI(bool*);
~box_sdl_engine(void);
//game constants -------------
const float worldOffset;
const int screenWidth;
const int screenHeight;
const float32 timeStep ;
const int32 iterations ;
const float pixelToMeter ;
const float meterToPixel ;
const float xSpeed;
const float motorSpeed;
//DATA========================
b2Contact *cpList;
box_sdl_engine(void);
SDL_Surface *screen;
SDL_Event Event ;
b2World *worldBox;
std::vector<Object*> objectList;
std::vector<Player*> playerList;
b2PrismaticJoint* player1pad;
b2PrismaticJoint* player2pad;
};
box_sdl_engine::box_sdl_engine(void):
worldOffset(50.0f),
timeStep(1.0f/45.0f),
iterations(10),
pixelToMeter(1.0f/16.0f),
meterToPixel(16.0f),
screenHeight(600),
screenWidth(800),
motorSpeed(100.0f),
xSpeed(30.0f)
{
box_sdl_engine::instance = this;
//initialize Box2d
b2AABB worldAABB;
worldAABB.lowerBound.Set(-worldOffset ,-worldOffset );
worldAABB.upperBound.Set((screenWidth + worldOffset), (screenHeight + worldOffset));
b2Vec2 gravity(0.0f, 0.0f *this->pixelToMeter);
this->worldBox = new b2World(worldAABB,gravity,true);
//initialize SDL
SDL_Init(SDL_INIT_VIDEO);
//TTF_Init();
}
#pragma once
//#include "stdafx.h"
#include "sdl.h"
#include <string>
#include "Box2D.h"
class Object
{
public:
Object(void);
Object(std::string Name, bool IsStatic,float x, float y);
~Object(void);
void Draw(SDL_Surface* screen);
//private:
SDL_Surface *surface;
std::string name;
bool isStatic;
b2Body* shape;
float hw;
float hh;
};
#include <vector>
#include "Box2D.h"
#include "sdl.h"
//#include "sdl_ttf.h"
#include "Object.h"
#include "Player.h"
class box_sdl_engine
{
public:
static box_sdl_engine *instance;
//Functions==================
void renderScreen();
int getPlayers(void);
void showScore(bool*);
int RunGame(int);
bool announceWinner(int);
int InitGame();
void EndGame(void);
int getAI(bool*);
~box_sdl_engine(void);
//game constants -------------
const float worldOffset;
const int screenWidth;
const int screenHeight;
const float32 timeStep ;
const int32 iterations ;
const float pixelToMeter ;
const float meterToPixel ;
const float xSpeed;
const float motorSpeed;
//DATA========================
b2Contact *cpList;
box_sdl_engine(void);
SDL_Surface *screen;
SDL_Event Event ;
b2World *worldBox;
std::vector<Object*> objectList;
std::vector<Player*> playerList;
b2PrismaticJoint* player1pad;
b2PrismaticJoint* player2pad;
};
box_sdl_engine::box_sdl_engine(void):
worldOffset(50.0f),
timeStep(1.0f/45.0f),
iterations(10),
pixelToMeter(1.0f/16.0f),
meterToPixel(16.0f),
screenHeight(600),
screenWidth(800),
motorSpeed(100.0f),
xSpeed(30.0f)
{
box_sdl_engine::instance = this;
//initialize Box2d
b2AABB worldAABB;
worldAABB.lowerBound.Set(-worldOffset ,-worldOffset );
worldAABB.upperBound.Set((screenWidth + worldOffset), (screenHeight + worldOffset));
b2Vec2 gravity(0.0f, 0.0f *this->pixelToMeter);
this->worldBox = new b2World(worldAABB,gravity,true);
//initialize SDL
SDL_Init(SDL_INIT_VIDEO);
//TTF_Init();
}
#pragma once
//#include "stdafx.h"
#include "sdl.h"
#include <string>
#include "Box2D.h"
class Object
{
public:
Object(void);
Object(std::string Name, bool IsStatic,float x, float y);
~Object(void);
void Draw(SDL_Surface* screen);
//private:
SDL_Surface *surface;
std::string name;
bool isStatic;
b2Body* shape;
float hw;
float hh;
};
I hope this helps.
Original thread: https://box2d.org/forum/viewtopic.php?t=1171