Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, SBGuy, TipmyPip, ozgur), 923 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Rocket Lib for LiteC [Re: Talemon] #417585
02/14/13 09:00
02/14/13 09:00
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,



I have also tried librocket (while Panda3D 1.8 has been released). I think that your problem is with render states (Some states used by the engine are [incompatible] with the states required to render librocket). It is possible to make them work together ( I have tried using a naive aproach that caused some slowdown), but you need to identify those states and enable/disable them based on the context you wand to render (librocket/engine). Renderering librocket on a BMAP (and a better input integration) is also something that needs more investigation.

GWEN also is good (More components but with traditional GUI programming - no HTML/CSS - Can be good for tools) (http://code.google.com/p/gwen/) but the last time I tried it (while it was hosted at code.google.com) it had some bugs with tree components. Now it is hosted on github and seems to be actively developed again.

Re: Rocket Lib for LiteC [Re: 3dgs_snake] #417589
02/14/13 09:40
02/14/13 09:40
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
This "gwen" looks really good!
I think I'll give it a try laugh

Re: Rocket Lib for LiteC [Re: Ch40zzC0d3r] #417591
02/14/13 10:43
02/14/13 10:43
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
@Talemon: Yeah, but I see no line that loads something like an example GUI or so?

@3dgs_snake: As we can see from your screenshots, you were successful with implementing RocketLib, so why don't you tell Talemon the necessary render states and what he has to change??

Re: Rocket Lib for LiteC [Re: HeelX] #417596
02/14/13 11:07
02/14/13 11:07
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline
Junior Member
Talemon  Offline
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
@HeelX: It's in the DLL as I just wanted it to render something, I was planning to add functions to manage it from lite-c.

Line 62 on:
https://github.com/talemon/alibrocket/blob/master/alibrocket/alibrocket.cpp

@3dgs_snake: well, as he said, it would be nice if you could share what you did to make it work.

Last edited by Talemon; 02/14/13 11:09.
Re: Rocket Lib for LiteC [Re: HeelX] #417597
02/14/13 11:07
02/14/13 11:07
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Like I said, I really don't know. I just saved all render states, reset, apply librocket states (That's what I called naive approach and slow). Also, that was exactly 1 year ago blush . Bellow is the C++ code I used to test the lib (Before creating a plugin, I test it using Win App) if that can help you (I think that only the states that are used by librocket and 3dgs need to be changed).

PS : As I said, it is only a dirty code I used to test if a 3dgs plugin can be created using librocket wink .

Code:
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <string>

#include <var.h>
#include <adll.h>

#include <Rocket\Core.h>
#include <Rocket\Controls.h>
#include <Rocket\Debugger.h>

#include "RenderInterfaceDirectX.h"
#include "Input.h"
#include "InputWin32.h"

// Engine vars
ENGINE_VARS *ev = NULL;

LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;

Rocket::Core::Context *context = NULL;             

IDirect3DStateBlock9* pStateBlock = NULL;
IDirect3DStateBlock9* pStateBlock2 = NULL;

// System Interface
class GSSystemInterface : public Rocket::Core::SystemInterface
{
public:
	virtual float GetElapsedTime(); 
};

float GSSystemInterface::GetElapsedTime()
{
	return v(total_ticks) * 0.16;
}

// Load default fonts
void LoadFonts()
{
	Rocket::Core::String font_names[5];
	font_names[0] = "Delicious-Roman.otf";
	font_names[1] = "Delicious-Italic.otf";
	font_names[2] = "Delicious-Bold.otf";
	font_names[3] = "Delicious-BoldItalic.otf";
	font_names[4] = "Comica BD.ttf";

	for (int i = 0; i < sizeof(font_names) / sizeof(Rocket::Core::String); i++)
	{
		Rocket::Core::FontDatabase::LoadFontFace(Rocket::Core::String("assets/") + font_names[i]);
	}
}

// Set renderStates for rocket
void SetRenderStates()
{
	// Get screen size
	VECTOR screen_size;
	vec_set(&screen_size, &v(screen_size));
	
	// Save State block before
	// Save current stateblock
	g_pd3dDevice->CreateStateBlock( D3DSBT_ALL, &pStateBlock2);
	//Restore state block
	pStateBlock->Apply();
	
	// Set up an orthographic projection.
	D3DXMATRIX projection;
	D3DXMatrixOrthoOffCenterLH(&projection, 0, screen_size.x, screen_size.y, 0, -1, 1);
	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &projection);

	// Switch to clockwise culling instead of counter-clockwise culling; Rocket generates counter-clockwise geometry,
	// so you can either reverse the culling mode when Rocket is rendering, or reverse the indices in the render
	// interface.
	//g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);

	// Enable alpha-blending for Rocket.
	g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_BOTHSRCALPHA);
	g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_BOTHINVSRCALPHA);

	// Set up the texture stage states for the diffuse texture.
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

	g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

	// Disable lighting for Rocket.
	g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

	//g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, 2);
}

// Event Handlers Declaration
// Store Original message handler
WNDPROC OriginalHandler = NULL;
// Create a neww handler for rocket
LRESULT CALLBACK AckRocketEventHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	// Process Input
	InputWin32::ProcessWindowsEvent(msg, wParam, lParam);
	// Call OriginalHandler
	return OriginalHandler(hWnd, msg, wParam, lParam);
}

VOID WINAPI ColorFill (D3DXVECTOR4* pOut, const D3DXVECTOR2* pTexCoord, 
const D3DXVECTOR2* pTexelSize, LPVOID pData)
{
    //*pOut = D3DXVECTOR4(pTexCoord->x, pTexCoord->y, pTexCoord->x + pTexCoord->y, 1.0f);
	*pOut = D3DXVECTOR4(pTexCoord->x, pTexCoord->y, pTexCoord->x + pTexCoord->y, 1.0f);
}

// WinMain
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCMd)
{
	// Open engine
	ev = engine_open("");

	// Create Rendering engine
	engine_frame();
	
	//level_load(NULL);
	vec_set((VECTOR *)&v(screen_color), vector(255, 0, 0));
	//level_load(NULL);
	//v(camera).size_x = 100;
	//v(camera).size_y = 100;
	
	// Get DirectX interface
	g_pd3dDevice = (LPDIRECT3DDEVICE9)draw_begin();
	if (g_pd3dDevice == NULL)
	{
		return -1;
	}
	// Save current stateblock
	g_pd3dDevice->CreateStateBlock( D3DSBT_ALL, &pStateBlock );

	// Test level load
	v(logo) = 1;
	//level_load(NULL);
	//ENTITY *ent = ent_create("CUBE.MDL", vector(0, 0, 0), NULL);
	//ent->x += 100;
	//v(fps_max) = 60;
	// Display panel
	PANEL *pan = pan_create("", 0);
	pan->flags = SHOW;
	BMAP *bmp = bmap_createblack((v(screen_size).x * 0.5f), (v(screen_size).y * 0.5f), 32);
	pan->bmap = bmp;
	bmap_fill(bmp, (COLOR *)vector(0, 0, 255), 100);

	level_load("");

	var frames = 0;
	var fps = 0;
	pan_setdigits(pan, 0, 10, 200, "Variable acknex = %5.0f", NULL, 16, &fps);

	// Initialize librocket
	GSSystemInterface sysInterface;
	Rocket::Core::SetSystemInterface(&sysInterface);

	RenderInterfaceDirectX directx_renderer((LPDIRECT3D9)NULL, g_pd3dDevice);
	Rocket::Core::SetRenderInterface(&directx_renderer);
	
	// Init Rocket
	Rocket::Core::Initialise();
	// Init controls
	Rocket::Controls::Initialise();

	// Initialize keymap
	InputWin32::Initialise();
	// Bind event handler
	OriginalHandler = (WNDPROC) *ev->on_message;
	*ev->on_message = (EVENT)AckRocketEventHandler;

	// define a suited vertex struct
	typedef struct VERTEX_FLAT { 
		float x,y,z; 
		float rhw; 
		D3DCOLOR color; 
	} VERTEX_FLAT;
	#define D3DFVF_FLAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

	// define the three corner vertices
   VERTEX_FLAT v[3];
   v[0].x = 10.0; v[0].y = 10.0; v[0].color = 0xFFFF00FF; // the red corner
   v[1].x = 310.0; v[1].y = 10.0; v[1].color = 0xFF0000FF; // the blue corner
   v[2].x = 10.0; v[2].y = 310.0; v[2].color = 0xFF00FFFF; // the green corner
   v[0].z = v[1].z = v[2].z = 0.0; // z buffer - paint over everything
   v[0].rhw = v[1].rhw = v[2].rhw = 1.0; // no perspective

	// Engine loop
	while(engine_frame())
	{
		g_pd3dDevice = (LPDIRECT3DDEVICE9)draw_begin();
		SetRenderStates();

		fps = 0.9*fps + 0.1 / v(time_frame); 

		//ent->pan += 5 * v(time_step);

		if (context != NULL)
		{
			context->Update();
			context->Render();

			// Restore stateBlock
			pStateBlock2->Apply();
		}
		else
		{
			// Initialize context
			// CReate the main Rocket context and set it to the input layer
			VECTOR screen_size;
			vec_set(&screen_size, &v(screen_size));
			//(int)screen_size.x, (int)screen_size.y)
			context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(screen_size.x, screen_size.y));
			
			/*TCHAR buff[255];
			wsprintf(buff, TEXT("Sizes = %d, %d"), context->GetDimensions().x, context->GetDimensions().y);
			MessageBox(NULL, buff, TEXT("Screen sizes"), MB_OK);*/

			Rocket::Debugger::Initialise(context);
			Rocket::Debugger::SetVisible(true);
			Input::SetContext(context);

			// Load Core fonts
			LoadFonts();
			// Load and show the tutorial document.
			Rocket::Core::ElementDocument* document = context->LoadDocument("hassets/window.rml");
			if (document != NULL)
			{
				document->Show();
				document->RemoveReference();
			}
		}
	}

	// Close acknex engine
	engine_close();

	// Return success
	return 0;
}


Re: Rocket Lib for LiteC [Re: 3dgs_snake] #417602
02/14/13 11:58
02/14/13 11:58
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline
Junior Member
Talemon  Offline
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
I'll take a look at it, thank you very much for such a quick response (:

Re: Rocket Lib for LiteC [Re: Talemon] #417639
02/14/13 21:09
02/14/13 21:09
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
@3dgs_snake
How did you use gwen with lite-c?
Did you create a dll and import gwen sdk?

Re: Rocket Lib for LiteC [Re: Ch40zzC0d3r] #417658
02/15/13 05:21
02/15/13 05:21
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
You need to create a gwen lib (static or dynamic) plus the directx-9 renderer lib. You then use them in a 3dgs plugin or C/C++ app. You can look into the DX9 sample to see how.

Re: Rocket Lib for LiteC [Re: 3dgs_snake] #417693
02/15/13 15:17
02/15/13 15:17
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Thanks, I got it working so far, but Ive got some problems.
1. On resizing the window Im crashing but IDK what pointer is invalid
2. I tried hooking GS MessageHandler to handle all the window messages with the gui function:

Code:
typedef LRESULT (CALLBACK *tMessageHandler)(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
tMessageHandler oMessageHandler;

LRESULT CALLBACK hkMessageHandler(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	MessageBoxA(NULL, "LOL", "LOL", MB_OK);

	return oMessageHandler(hwnd, message, wParam, lParam);
}

oMessageHandler = (tMessageHandler)(ev->on_message);
ev->on_message = (EVENT*)hkMessageHandler;



But the MsgBox never pops up.
Please help me frown

Re: Rocket Lib for LiteC [Re: Ch40zzC0d3r] #417720
02/16/13 12:41
02/16/13 12:41
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Just fixed the messagehandler error, but I always crash on changing resolution while drawing the gui, I tried hooking Reset, or checking if device or screen_size chnaged but it seems its crashing before I can stop drawing.
Any Idea how to fix that?
I think I will release the GUI here if I fixed those bugs laugh

EDIT: Fixed that bug!
Simply hook reset and do this before calling the orig function:
Code:
if(pRenderer)
	pRenderer->Release();


Last edited by Ch40zzC0d3r; 02/16/13 16:02.
Page 2 of 2 1 2

Moderated by  aztec, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1