Jump to content

Recommended Posts

Posted

Please take a look, have no idea if/how i have to reload the framework or whatnot :

 

#include "engine.h"
#include <algorithm>
#include <vector>

using namespace std;

// possibleResolutions
vector<POINT> gPossibleResolutions;
unsigned int gCurrentResolution = 0;

bool operator==(const POINT& lhs, const POINT& rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y;
}

int WINAPI WinMain( HINSTANCE hInstance,
				HINSTANCE hPrevInstance,
				LPSTR lpCmdLine,
				int nShowCmd ) 
{
//intro
MessageBoxA(NULL,"Controls: Press ENTER to switch to next resolution possible on your system.", "Welcome to the Leadwerks Resolution Change Demo",MB_OK|MB_ICONINFORMATION);

// Ask The User Which Screen Mode They Prefer
bool fullscreen = (MessageBoxA(NULL,"Would You Like To Run In fullscreen mode?", "Fullscreen Mode?",MB_YESNO|MB_ICONQUESTION)==IDYES);

// get possible resolutions
bool success; 
int i = 0;
do
{
	DEVMODE devMode = {0}; 
	devMode.dmSize = sizeof(DEVMODE);
	success = EnumDisplaySettings(NULL,i,&devMode); 
	i++;
	if(success)
	{
		POINT resolution = {devMode.dmPelsWidth, devMode.dmPelsHeight};
		if(find(gPossibleResolutions.begin(),gPossibleResolutions.end(),resolution) == gPossibleResolutions.end())gPossibleResolutions.push_back(resolution);
	}
}
while(success);

Initialize() ;
RegisterAbstractPath("Path-To-SDK");
SetAppTitle( "LE_Resolution_Demo" ) ;

Graphics(gPossibleResolutions[gCurrentResolution].x, gPossibleResolutions[gCurrentResolution].y, fullscreen * 32); 
SetFocus(GetActiveWindow());

AFilter() ;
TFilter() ;

TWorld  world;
TCamera camera;

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

//	TBuffer renderbuffer = CreateBuffer(GraphicsWidth(), GraphicsHeight(), BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL);

// recreating the font ??

TFramework framework=CreateFramework();
TLayer layer = GetFrameworkLayer(0);

camera=GetLayerCamera(layer);
CameraRange(camera, .1f, 10000);
PositionEntity(camera,Vec3(0,0,-2));

//Set Lua variable
BP L=GetLuaState();
lua_pushobject(L,framework);
lua_setglobal(L,"fw");
lua_pop(L,1);

SetStats( 0 );
SetBackgroundMode(1);
SetBackgroundColor(Vec4(0.12f, 0.12f, 0.12f, 1));

SetHDR( true );
SetGodRays( true);
SetFarDOF( true);
SetFarDOFStrength(0.025f);
SetFarDOFRange(100, 1000);
/*
// is lost on init
SetContrast( 1.2f );
SetSaturation(.8f);
SetBrightness(.96f);
*/

/*
// is in the scene ...
// is lost on resolution change
sun = CreateDirectionalLight();
RotateEntity  ( sun, Vec3(33, 45, 0) );
*/

TModel scene = LoadScene("abstract::default_terrain.sbx");
TBody spectator = CreateBodySphere();

SetBodyMass(spectator, 1);
SetBodyGravityMode(spectator, 0);
SetBodyDamping(spectator, 1.0);
SetBodyElasticity(spectator, 1.0);

PositionEntity(spectator, Vec3(0, 0, -25) );

float mx=0.0,my=0.0;
float move=0.0, strafe=0.0;
float mincamXangle=-89, maxcamXangle=89;
TVec3 camrotation;

HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

// Game loop
while( !KeyHit() && !AppTerminate() )
{
		if( !AppSuspended() ) // We are not in focus!
		{
			// change resolution?
			if(KeyHit(KEY_ENTER) || gCurrentResolution == -1)
			{
				gCurrentResolution++;
				if(gCurrentResolution >= gPossibleResolutions.size())
					gCurrentResolution = 0;

				// reset graphics and recreate
				// FreeBuffer(renderbuffer); //???

				Graphics(gPossibleResolutions[gCurrentResolution].x, gPossibleResolutions[gCurrentResolution].y, fullscreen * 32); 
				SetFocus(GetActiveWindow());
				// renderbuffer = CreateBuffer(GraphicsWidth(), GraphicsHeight(), BUFFER_COLOR0|BUFFER_DEPTH|BUFFER_NORMAL);
			}

			//================================================================
			//Camera looking
			mx=Curve(MouseX()-float(GraphicsWidth()/2),mx,6);
			my=Curve(MouseY()-float(GraphicsHeight()/2),my,6);

			MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

			camrotation=EntityRotation( camera );
			camrotation.X+=my * 0.1f;
			camrotation.Y-=mx * 0.1f;
			camrotation.X=Clamp(camrotation.X, mincamXangle, maxcamXangle);

			RotateEntity(camera, camrotation);

			//Camera movement
			move=float(KeyDown(KEY_W)-KeyDown(KEY_S));
			strafe=float(KeyDown(KEY_D)-KeyDown(KEY_A));

			TVec3 force = Vec3(strafe*13.f, 0, move*13.f);
			force = TFormVector(force, camera, 0);
			AddBodyForce(spectator, force);

			//Position the camera where the spectator body is
			PositionEntity(camera, EntityPosition(spectator) );
			//================================================================

			// Update timing and world
			UpdateFramework();

			// Render
			RenderFramework();

			// FPS and some other on screen info
			/*
			char s[256] ;
			SetBlend(BLEND_ALPHA);
			SetColor(Vec4(.9f, .6f, .4f, .7f));
			sprintf_s(s,"FPS: %.0f",UPS()); 
			DrawText (0, 0, s);
			sprintf_s(s,"%d polys",TrisRendered( true )); 
			DrawText (0, 15, s);
			sprintf_s(s,"Pos (%.2f,%.2f,%.2f)", EntityPosition(camera, 0).X, EntityPosition(camera, 0).Y, EntityPosition(camera, 0).Z );	 
			DrawText (0, 30, s);

			SetColor(Vec4(.95f, .64f, .43f, 1));
			sprintf_s(s,"Current resolution: %d, %d",GraphicsWidth(), GraphicsHeight());
			DrawText (0, 45, s);
			SetBlend(0);
			SetColor(Vec4(1));
			*/
			// Send to screen
			Flip(1) ;
		}
}

// Done
return Terminate() ;
}

 

thanks ...

 

[edit][bug]

Beware - I used to use (haha) this code to debugg my postprocessing effects but came to the conclusion that its causing bugs in conjunction with a LUA world e.g. makes SweptCollision FOBAR. Again - its an on/off behavior which makes debugging very annoying. At least drop everything between RenderFramework() and Flip(1).

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Posted

You should be able to change graphics resolution without having to reload anything.

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

  • 3 weeks later...
Posted

So it should work if I simply do:

 

Graphics(800,600);

 

... because in my case, the window is resized to the new resolution, but it is just plain black^^ I'm using framework and displaying a few images and texts. Do I have to reload those images?

Posted

You have to recreate the buffers according to the new size. calling Graphics() just creates (or replaces) the special "BackBuffer()" with the supplied parameters. If you use the project wizard, the buffer it calls gbuffer, has to be recreated manually.

LE Version: 2.50 (Eventually)

Posted

The framework class should detect the resolution change automatically and recreate the buffers on its own.

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

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.

×
×
  • Create New...