-
Posts
230 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Posts posted by Charrua
-
-
find a way to send keystrokes!
i'm using something like:
WebKeyboardEvent keyEvent; char chr; for (int i=1; i<256; i++){ char chr=i; keyEvent.type = WebKeyboardEvent::kTypeKeyDown; keyEvent.native_key_code = chr; webView->InjectKeyboardEvent(keyEvent); keyEvent.type = WebKeyboardEvent::kTypeChar; keyEvent.text[0] = chr; webView->InjectKeyboardEvent(keyEvent); keyEvent.type = Awesomium::WebKeyboardEvent::kTypeKeyUp; keyEvent.native_key_code = chr; webView->InjectKeyboardEvent(keyEvent); }
with this code, there are no A/a upper/lower
so some key mapping will be necessary
-
thank's for sharing
-
OK, thank's to Rick y now have a complete working example of integrating leadwerks and awesomium
the example now has 2 buttons, one to SayHello the other to exit the application and work as expected!
7z file has the Source folder with all the source files needed, those files which came from awesomium form part of one of the tutorials
general gelp on awesomium:
http://wiki.awesomium.com/getting-started/
tut files:
https://github.com/awesomium/tutorial-framework/archive/master.zip
complete c++ source and executable for you to try:
https://dl.dropboxusercontent.com/u/78894295/leadwerks/awe1.7z
had happens to me that the first time i run seem not to respond to mouse down events... but works ok if exit and run again
do not know why can it be!
enjoy
jio
-
at least should be goo to get a working all included example to start with
I'll will update this thread as soon as i get something new to show.
(too much information for me to digest.. it will take a while...)
thank's again
jio
-
rick, i was writing my second post when you answer my first
thank's for your input, i have to read it carefully
about keyboard input... je je, the docs say not to much... even tells us to read some other doc which has no link!
would be nice if some one else has a code for that
jio
-
forgot to include an executable for you to try
if you change the boton.html for another more elaborated html it should work also.
but i'm only using 300x200 pixels for the ui texture, so not too much space for being much creative.
int the app dir, a snapshoot of the html as is after loaded is saved as result.jpg
here the 7z file:
https://dl.dropboxusercontent.com/u/78894295/leadwerks/awe.7z
enjoy
jio
-
Hi, i was trying to get awesomium to work with leadwerks.
Mi knowledge about javascript and html are almost nothing, (ok, my knowledge of c++ isn't too much also)
I need a ui for leadwerks, which is a must, i guess.
The following code is what i could make to work:
1) load a local html file
2) on every loop
send mouse events to the html "web view"
get how it look on a leadwerks texture
show it on the screen (context->DrawImage)
What i miss is how to bind java events to c++ functions
Does someone has a simple example of how to do that.
A snapshoot:
here the complete source:
/* Awesomium - Leadwerks tests by Juan Ignacio Odriozola, aka charrua http://wiki.awesomium.com/getting-started/ What this code does load a simple html page: just a label and a button get what it show and copy that info to a Leadwerks texture Send to the html mouse events Display the texture on screen with a cube rotating on the 3d space if you hover the button, mouse down or mouse up, the control draws as spected. What it doesn't the code do not bind button press and do not call any c++ function OnMouseHit SO I'm asking if anyone has a simple code to showme how to do that. I'm know nothing about html neither javascript, i will try to learn abot them if i got awesomium to work with leadwerks! Hope this code will catch interest in other about awesomium or short the learning path that's the html source of "boton.html": <html> <body> <h1>Awesomium Test</h1> <button onclick="app.sayHello()">Say Hello</button> </body> </html> */ #include "App.h" #include <Awesomium/WebCore.h> #include <Awesomium/BitmapSurface.h> #include <Awesomium/STLHelpers.h> using namespace Awesomium; WebCore* web_core = NULL; WebView* my_web_view = NULL; BitmapSurface* uiSurface = NULL; Texture* uiTex = NULL; unsigned char* pixels = NULL; using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* model = NULL; JSValue jsResult; bool App::Start() { window = Window::Create(); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 0, -3); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); // Create the WebCore singleton with default configuration web_core = WebCore::Initialize(WebConfig()); // al salir: WebCore::Shutdown(); my_web_view = web_core->CreateWebView(320, 200); WebURL url(WSLit("file:///./boton.html")); //acceso al dir local! my_web_view->LoadURL(url); uiTex = Texture::Create(320, 200); pixels = (unsigned char*)malloc(uiTex->GetMipmapSize(0)); // Wait for our WebView to finish loading while (my_web_view->IsLoading()) web_core->Update(); Sleep(300); web_core->Update(); uiSurface = (BitmapSurface*)my_web_view->surface(); // para esto hay que: #include <Awesomium/BitmapSurface.h> if (uiSurface != 0) { uiSurface->SaveToJPEG(WSLit("./result.jpg")); //just to verify html was loaded and how it look! uiSurface->CopyTo(pixels, uiTex->GetWidth() * 4, 4, true, false); uiTex->SetPixels((char*)pixels); } // now a cube and btw texture it with the html view //Create a material Material* material = Material::Create(); //use uiTex as texture material->SetTexture(uiTex); //Load and apply a shader Shader* shader = Shader::Load("Shaders/Model/diffuse.shader"); material->SetShader(shader); shader->Release(); //Create a model and apply the material model = Model::Box(); model->SetMaterial(material); model->SetPosition(0, 0, 1); return true; } bool mouseLeftDown = false; bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) { free(pixels); my_web_view->Destroy(); WebCore::Shutdown(); return false; } model->Turn(Time::GetSpeed()/3, Time::GetSpeed()/4, Time::GetSpeed() / 2); //get new pixel data from html view if (uiSurface != 0) { uiSurface->CopyTo(pixels, uiTex->GetWidth() * 4, 4, true, false); uiTex->SetPixels((char*)pixels); } // Inject a mouse-movement my_web_view->InjectMouseMove(window->MouseX(), window->MouseY()); if (window->MouseDown(1)){ // Inject a left-mouse-button down event my_web_view->InjectMouseDown(kMouseButton_Left); mouseLeftDown = true; } else { if (mouseLeftDown) { mouseLeftDown = false; // Inject a left-mouse-button up event my_web_view->InjectMouseUp(kMouseButton_Left); } } web_core->Update(); Time::Update(); world->Update(); world->Render(); context->DrawImage(uiTex, 0, 0); context->Sync(); return true; }
more snapshoots, when mouse hover the button and when i'ts clicked
thank's in advance
jio
-
ok solved the init errors.. (most my fault)!
now, i think i get lost forever, when i try to update the gui, then:
Unhandled exception at 0x0F2B5C8D (AlbaLynx.dll) in jio.debug.exe: 0xC0000005: Access violation reading location 0x00000000.
i tested version 1060 and 1110, 1060 do not pass the initiate function
version 1110 pass the init (initiate is deprecated in this new version) so some checks like valid window and graphics devices are passed.
i can call many of the functions to create and set parameters, just update seems to fail
-
Hey, thank's for you fast response:)
the first step seemed to be the easiest one and... i'm stuck on it!
Transfer functions to AlbaLynx [C++]
If you are using C++, then the easiest way is to create a derived class based on cALInput:
class cInput : public cALInput {
public:
// Implementation of abstract methods
virtual int MouseX() { … }
…
virtual void FlushMouse() { … }
};
In the constructor of the base class (cALInput) a pointer to an instance of this class is written in a static variable, so that the GUI can refer to it.
Before initializing the GUI, simply create an instance of this class:
// Connect AlbaLynx to input system
cInput input;
but when i call the init function the message isn't about window o graphics pointers ... is about that the pointer to input is null.
so... i'll keep trying
-
Hi
i'm trying to connect Leadwerks to a gui, which development has stopped, but that i used and use at present with other engines (albalynx).
One of the firsts steps consist in passing pointers of the window's window and the graphics device (openGL i guess), albalynx is supposed to support DirecX9,10,11 and OpenGL 4
I found some functions and properties like:
Context* context->getCurrent();
Window* window->getCurrent();
window->whnd;
i readed about Window:GetHandle()
but seems to not exists.
any help is appreciated!
thank's in advance
jio
-
i always been interested in this subject
i know that the following isn't the best way, but is better than nothing
basically i use the GetKeyValue and SetKeyValue to store pairs: key,value on a "messenger" entity
i create a pivot named "messenger" in my map (or the number needed) and name it the same
then in c++ scan the world.entities and catch that entity.
once i have it's handle (address, pointer...) then i have a simple, brute force, but working line of comunication:
-------------------------------------------------- more explained
create a messenger object (a pivot) in your map
name it "messenger"
in your lua start function you may:
self.messenger:SetKeyValue("Hit","0")
self.messenger:SetKeyValue("xPos","0")
self.messenger:SetKeyValue("yPos","0")
-------------------------------- c++ side
Entity* messenger;
//after map load
for (auto e : world->entities){
if (e->GetKeyValue("name") == "messenger"){
messenger = e; //catch messenger entity
}
}
//from c++
ent->SetKeyValue("Hit", "1"); //set Hit property to 1 to signal something spected in lua
--------------------------------- lua side
//UpdateWorld perhaps
if self.messenger:GetKeyValue("Hit")=="1" then
self.messenger:SetKeyValue("Hit","0") // may signal : readed
//do whatever HIT does/needs
end
(sorry my bad English)
Juan
- 1
-
thxs
i'm going to do so
i receive a pm from josh about a steam key
so, thread resolved!
-
i have the stand alone version
3.3 is only for the ones that has steam version?
my updater tells me that there are no files to update.
do i have access to that version?
do i have to pay for it?
i was off for a while, do i miss something obvious?
thank's in advance
Juan
-
hi
i am getting some troubles, due to my lack of knowledge.
the easy part is:
add
#include "lua.h"
in your App.h
so, any scripted object will work, but:
if you create a camera in your map (via editor) you have to make some tricks to use that camera and not create another via c++
your initila c++ code, creates a context, window etc, you have to write your scripts using those objects...
you may write something like this on your Scripts functions:
function Script:PostRender()
local window = Window:GetCurrent()
local context = Context:GetCurrent()
if window:KeyHit(Key.M) then
self.showtext = not(self.showtext)
end
if self.showtext
context:SetBlendMode(Blend.Alpha)
context:SetColor(255,255, 255)
context:DrawText("hello", x, y)
end
end
as i get some troubles using a camera defined in c from lua scripts (sure i am doing something wrong) i define the camera inside the editor and then i use that camera from c++
see:
http://www.leadwerks.com/werkspace/topic/10154-set-camera-to-a-camera-in-the-scenelevelmap/
Juan
-
thank's i have to seriously start studying c++ and lua
by the moment i have to evade call a script function from c++, till i get older!
thank's again
-
i have many objects with scripts attached
if i get one of them via collision or ray pick, can i call a function declared inside the entity's script?
something like
pickinfo.entity.script.Hit(), if Hit is defined inside the script
thank's in advance
Juan
-
i used this to use an entity rotation and transform it to a normalized rotation, perhaps is very indirect, but seems to work
guess there should be a simpler mathematical way, but still unknown for me.
hope that helps:
if self.usepivotpin then local pvtTemp = Pivot:Create() --get ent rotation, to set hinge pin if pvtTemp ~= nil then pvtTemp:SetRotation(self.entity:GetRotation()) pvtTemp:Move(0,0,1) --transform from euler angles to 0..1 axis coords ... a vector of lenght one: nomarized local rot = pvtTemp:GetPosition(false) self.pin.x = rot.x self.pin.y = rot.y self.pin.z = rot.z --System:Print("pin: " .. self.pin.x .. ", " .. self.pin.y .. ", " .. self.pin.z) pvtTemp:Release() end end
i used to set hinge joint pin, btw
-
there are some spanish speakers over there (like me!) but unfortunately i'm new here and probably has more questions than you.
HI!
- 1
-
this fragment must be in app.cpp before start() function
this is my complete App.cpp:
#include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Vec3 camerarotation; #if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS) bool freelookmode=true; #else bool freelookmode=false; #endif //Store entities vector<Entity*> entities; //Store all entities when map is loaded void StoreWorldObjects(Entity* entity, Object* extra) { System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name") + " /" + entity->GetKeyValue("anInt") + "/" + entity->GetKeyValue("aString")+"/"); entities.push_back(entity); } bool App::Start() { //Initialize Steamworks (optional) /*if (!Steamworks::Initialize()) { System::Print("Error: Failed to initialize Steam."); return false; }*/ //Create a window window = Leadwerks::Window::Create("GetMapEntity"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); //Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); Map::Load(mapname, StoreWorldObjects); vector<Entity*>::iterator iter = entities.begin(); int id = 0; for (iter; iter != entities.end(); iter++) { Entity* entity = *iter; System::Print(entity->GetKeyValue("name")); if (entity->GetKeyValue("name") == "EditorCamera"){ camera = entity; System::Print("found a camera in the editor"); } } if (camera == NULL) { System::Print("no camera from editor"); //Create a camera camera = Camera::Create(); camera->Move(0, 2, -5); } //Hide the mouse cursor window->HideMouse(); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2); freelookmode = false; return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) return false; //Press escape to end freelook mode if (window->KeyHit(Key::Escape)) { if (!freelookmode) return false; freelookmode=false; window->ShowMouse(); } if (freelookmode) { //Keyboard movement float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Leadwerks::Time::GetSpeed() * 0.05; float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Leadwerks::Time::GetSpeed() * 0.05; camera->Move(strafe,0,move); //Get the mouse movement float sx = context->GetWidth()/2; float sy = context->GetHeight()/2; Vec3 mouseposition = window->GetMousePosition(); float dx = mouseposition.x - sx; float dy = mouseposition.y - sy; //Adjust and set the camera rotation camerarotation.x += dy / 10.0; camerarotation.y += dx / 10.0; camera->SetRotation(camerarotation); //Move the mouse to the center of the screen window->SetMousePosition(sx,sy); } Leadwerks::Time::Update(); world->Update(); world->Render(); context->Sync(false); return true; }
-
@shadoh
*It's useful to search the map for key entities all at one time so you can reference them later. Example: Spawn Points, HeightMapI made a LoadMap function that wraps the Leadwerks LoadMap function to give all the extra functionality of referencing important entities, and in my case generating trees, and water
i use entities name's to embed csv's with extra info
i found a way in leadwerks to do so via SetKeyValue
with this simple script:
Script.AnInt=5--int "anInt" Script.AString="Hola"--string "string" function Script:Start() self.entity:SetKeyValue("anInt", self.AnInt) self.entity:SetKeyValue("aString", self.AString) end
attached to an entity you can pass any value, so you may have a general name: "WayPoint" and pass as keyvalues other properties not handled by the editor
you only has to use GetKeyValue from C++
System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name") + " /" + entity->GetKeyValue("anInt") + "/" + entity->GetKeyValue("aString")+"/");
- 1
-
did you declare the entities vector and the function?
//Store entities vector<Entity*> entities; //Store all entities when map is loaded void StoreWorldObjects(Entity* entity, Object* extra) { System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name")); entities.push_back(entity); }
-
map.cpp was posted by Josh
http://www.leadwerks.com/werkspace/topic/10139-leadwerks-map-class/
if you want to take a look.... and translate to some simple words....
-
AZ wrote:
Hi
I'm trying to set the camera to one I have in the scene
Currently I'm using one that is created, but I would like to switch to one that already is in the scene/level/map.
the situation, and i guess the needs of AZ was to get a camera created in the editor from c++
so, i created a camera in the editor, name it EditorCamera and then inside c++ i scan the list of objects and get's the "EditorCamera"entity
i create a camera only if i didn't found the one i created on the editor, because, as you said, having no camera is no sense.
in App.h, the variable camera is declared as Camera
if we change the declaration from Camera to Entity, then there are no problem and we can get the EditorCamera from the map and assign it to the global variable camera from c++
i'm just trying to solve the AZ trouble, and by te way, learning a bit more.
-
it works! thanks
declaring camear as entity in app.h was enough.
//Camera* camera; Entity* camera;
in App::Start() :
//Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); Map::Load(mapname, StoreWorldObjects); vector<Entity*>::iterator iter = entities.begin(); int id = 0; for (iter; iter != entities.end(); iter++) { Entity* entity = *iter; System::Print(entity->GetKeyValue("name")); if (entity->GetKeyValue("name") == "EditorCamera"){ camera = entity; System::Print("found a camera in the editor"); } } if (camera == NULL) { System::Print("no camera from editor"); //Create a camera camera = Camera::Create(); camera->Move(0, 2, -5); }
now i got the Editor Camera, it's position and orientation
works with freelookmode if i set it to true
Why use the editor camera and not the one created in c++?
For me is just a matter of connecting lua and c++
Perhaps editor is a better place to set the camera, position it etc
I'm not concerned only about cameras.
Probably in a near future, i will only use c++, but at this moment i'm using a combination and want to see how can i define one thing in the editor and have a reference from c++
thxs again
more than one view c++, found a way, need to know a better one :)
in Programming
Posted
Hi
I need 5 cameras and show what each is seeing in separate views.
the description of the function SetRenderTarget says:
so, i create the cameras, create the textures and set them as render target but textures don't get updated as i guessed.
so textures can be drawn on screen but don't get updated.
Searching i found this thread
http://www.leadwerks.com/werkspace/topic/13211-trouble-with-render-targets/page__hl__setrendertarget#entry93400
and seems that SetRenderTarget can't be used as i supposed it should be.
I started to use buffers but seems that i have to do one render world per camera/buffer to get what i want.
is it possible to do the same thing without 5 renders?
in a smart way which i don't imagine
here is the code i get working
thank's in advance
jio