Jump to content

C++ with Lua example


Josh
 Share

Recommended Posts

Make sure the "Scripts" folder is in the same directory as your program:

//	====================================================================
//	This file was generated by Leadwerks C++/LEO/BlitzMax Project Wizard
//	Written by Rimfrost Software
//	http://www.rimfrost.com 
//	====================================================================

#include "engine.h"

int WINAPI WinMain( HINSTANCE hInstance,
				HINSTANCE hPrevInstance,
				LPSTR lpCmdLine,
				int nShowCmd ) 
{
Initialize() ;
RegisterAbstractPath("C:/Program Files (x86)/Leadwerks Engine SDK");
SetAppTitle( "MyGame" ) ;
Graphics( 800, 600 ) ;
AFilter() ;
TFilter() ;

TWorld	world;
TBuffer gbuffer;
TCamera camera;
TMesh	mesh;
TLight	light;
TMesh	ground;
TMaterial material;

world = CreateWorld() ;
if (!world) {
	MessageBoxA(0,"Error","Failed to create world.",0);
	return Terminate();
}

gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

camera=CreateCamera();
PositionEntity(camera,Vec3(0,0,-20));

//================================================================
// Here is the code I added
//================================================================
SetGlobalObject("world_main",world);
LoadModel("abstract::windmill.gmf");
//================================================================
//
//================================================================

material=LoadMaterial("abstract::cobblestones.mat");

mesh=CreateCube();
PaintEntity(mesh,material);

ground=CreateCube();
ScaleEntity(ground,Vec3(10,1,10));
PositionEntity(ground,Vec3(0,-2,0));
PaintEntity(ground,material);

light=CreateDirectionalLight();
RotateEntity(light,Vec3(45,45,45));

// Game loop
while( !KeyHit() && !AppTerminate() )
{
	if( !AppSuspended() ) // We are not in focus!
	{
		// Rotate cube
		TurnEntity( mesh, Vec3( 0.5f*AppSpeed() ) ) ;

		// Update timing and world
		UpdateAppTime();
		UpdateWorld(AppSpeed()) ;

		// Render
		SetBuffer(gbuffer);
		RenderWorld();
		SetBuffer(BackBuffer());
		RenderLights(gbuffer);

		// Send to screen
		Flip(0) ;
	}
}

// Done
return Terminate() ;
}

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Thank's Josh, it worked great.

 

I converted it to use the Framewerk, but i can't get the blades to turn.

 

Here is the code i'm using, with SetGlobalObject();

 

#include "framewerk.h"
using namespace leadwerks;

int main()
{
       if(!Initialize())return 1;
       RegisterAbstractPath("C:/LE2.3");
       SetAppTitle( "C++ Lua Demo" ) ;
       Graphics( 800, 600 ) ;
       AFilter() ;
       TFilter() ;      

       TLight    light;
       TMesh	  ground;
       TMaterial material;

       Framewerk fw;

	if( !fw.Create() )
		{
			MessageBoxA(0,"Failed to initialize engine.",NULL,0);
			return 1;
		}



       //================================================================
       // Here is the code I added
       //================================================================
       SetGlobalObject("world_main",fw.GetMain().GetWorld());
       LoadModel("abstract::windmill.gmf");
       //================================================================
       //
       //================================================================

	fw.GetRenderer().SetSkybox( LoadMaterial("abstract::FullskiesBlueClear0016_2_L.mat") );
	fw.GetRenderer().SetSSAO(0);
	fw.SetStats(2); 

       PositionEntity(fw.GetMain().GetCamera(),Vec3(0,8,-22));

	material = LoadMaterial("abstract::cobblestones.mat");

	ground = CreateCube();
	ScaleEntity   ( ground, Vec3(12,  1, 12));
	PositionEntity( ground, Vec3(0, -1, 0));
	PaintEntity   ( ground, material );

       light=CreateDirectionalLight();
       RotateEntity( light, Vec3(45) );

       // Game loop
       do
	{
		if( KeyHit(KEY_ESCAPE) ) break;
		if( AppTerminate()     ) break;

		// Update timing and world
           //UpdateAppTime();
           //UpdateWorld(AppSpeed()) ;

           // Render

           fw.Update();
		fw.Render();

           // Send to screen
           Flip(0) ;
       }
	while( true );

       // Done
       return Terminate() ;
}

 

 

 

Is it possible to use Lua with Framewerk ?

post-23-12591255949605_thumb.jpg

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Link to comment
Share on other sites

It's working with Framewerk

smile.gif

 

All i had to add to my project was:

SetGlobalObject ("world_main", g_FW.GetMain ().GetWorld ());

SetGlobalObject ("world_transparency", g_FW.GetTransparency ().GetWorld ());

SetGlobalObject ("world_background", g_FW.GetBackground ().GetWorld ());

SetGlobalObject ("camera_main", g_FW.GetMain ().GetCamera ());

SetGlobalObject ("camera_transparency", g_FW.GetTransparency ().GetCamera ());

SetGlobalObject ("camera_background", g_FW.GetBackground ().GetCamera ());

g_FW is an instance of the Framewerk...obviously laugh.gif

 

 

Josh, you told us that LUA runs along with C++ with NO code changes...thats just not true!

I need the 6 lines above!! tongue.gif

 

 

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

  • 4 months later...

Hi,

I used ProjectWizard to create an empty project. Josh's code worked fine but when I create an instance of Framewerk I get these errors :

 

Error 1 error LNK2019: unresolved external symbol "public: virtual __thiscall leadwerks::Framewerk::~Framewerk(void)" (??1Framewerk@leadwerks@@UAE@XZ) referenced in function _WinMain@16 test_windows002.obj test_windows002

 

Error 2 error LNK2019: unresolved external symbol "public: __thiscall leadwerks::Framewerk::Framewerk(void)" (??0Framewerk@leadwerks@@QAE@XZ) referenced in function _WinMain@16 test_windows002.obj test_windows002

 

Error 3 fatal error LNK1120: 2 unresolved externals .\test_windows002-Debug.exe test_windows002

 

Here is my code:

//	====================================================================
//	This file was generated by Leadwerks C++/LEO/BlitzMax Project Wizard
//	Written by Rimfrost Software
//	http://www.rimfrost.com 
//	====================================================================

#include "engine.h"
#include "framewerk.h"
using namespace leadwerks;

int WINAPI WinMain( HINSTANCE hInstance,
				HINSTANCE hPrevInstance,
				LPSTR lpCmdLine,
				int nShowCmd ) 
{
Initialize() ;
RegisterAbstractPath("C:/Program Files/Leadwerks Engine SDK");
SetAppTitle( "test_windows002" ) ;
Graphics( 800, 600 ) ;
AFilter() ;
TFilter() ;

TWorld	world;
TBuffer gbuffer;
TCamera camera;
TMesh	mesh;
TLight	light;
TMesh	ground;
TMaterial material;

world = CreateWorld() ;
if (!world) {
	MessageBoxA(0,"Error","Failed to create world.",0);
	return Terminate();
}

Framewerk fw;


gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

camera=CreateCamera();
PositionEntity(camera,Vec3(0,0,-2));

material=LoadMaterial("abstract::cobblestones.mat");

mesh=CreateCube();
PaintEntity(mesh,material);

ground=CreateCube();
ScaleEntity(ground,Vec3(10,1,10));
PositionEntity(ground,Vec3(0,-2,0));
PaintEntity(ground,material);

light=CreateDirectionalLight();
RotateEntity(light,Vec3(45,45,45));

// Game loop
while( !KeyHit() && !AppTerminate() )
{
	if( !AppSuspended() ) // We are not in focus!
	{
		// Rotate cube
		TurnEntity( mesh, Vec3( 0.5f*AppSpeed() ) ) ;

		// Update timing and world
		UpdateAppTime();
		UpdateWorld(AppSpeed()) ;

		// Render
		SetBuffer(gbuffer);
		RenderWorld();
		SetBuffer(BackBuffer());
		RenderLights(gbuffer);

		// Send to screen
		Flip(0) ;
	}
}

// Done
return Terminate() ;
}

 

Can anybody help me please.

thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...