Jump to content

Charrua

Developers
  • Posts

    230
  • Joined

  • Last visited

Posts posted by Charrua

  1. Hi

     

    I need 5 cameras and show what each is seeing in separate views.

     

    the description of the function SetRenderTarget says:

    This functions sets a camera to render directly to a texture. The texture can be used in a material and applied to an object, or drawn onscreen.

     

    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 smile.png

     

    here is the code i get working

     

    #include "App.h"
    using namespace Leadwerks;
    App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
    App::~App() { delete world; delete window; }
    Model* models[5]; //just to show something
    Camera *cams[5]; // five cameras one for each view
    Buffer *buffs[5]; // one buffer per view
    const int numViews = 5;
    
    bool App::Start()
    {
    window = Window::Create();
    context = Context::Create(window);
    world = World::Create();
    Light* light = DirectionalLight::Create();
    light->SetRotation(35, 35, 0);
    // create one object per view
    models[0] = Model::Box();
    models[0]->SetColor(1.0, 0.0, 0.0);
    models[0]->SetPosition(-4, 0, 0);
    models[1] = Model::Cylinder();
    models[1]->SetColor(0.0, 1.0, 0.0);
    models[1]->SetPosition(-2, 0, 0);
    models[2] = Model::Cone();
    models[2]->SetColor(0.0, 0.0, 1.0);
    models[2]->SetPosition(0, 0, 0);
    models[3] = Model::Cylinder();
    models[3]->SetColor(0.0, 1.0, 1.0);
    models[3]->SetPosition(2, 0, 0);
    models[4] = Model::Box();
    models[4]->SetColor(1.0, 0.0, 1.0);
    models[4]->SetPosition(4, 0, 0);
    //create each camera and buffer
    for (int i = 0; i < numViews; i++){
    cams[i] = Camera::Create();
    cams[i]->Move(-4 + i * 2, 0, -6);
    cams[i]->Hide();
    buffs[i] = Buffer::Create(context->GetWidth() / numViews, context->GetHeight());
    }
    
    return true;
    }
    bool App::Loop()
    {
    if (window->Closed() || window->KeyDown(Key::Escape)) return false;
    for (int i = 0; i < numViews; i++){
    models[i]->Turn(Time::GetSpeed()*0.2*(i+1), 0, 0);
    }
    Time::Update();
    world->Update();
    
    for (int i = 0; i < numViews; i++){
    buffs[i]->Enable();
    cams[i]->Show();
    world->Render(); //is it neccesary to do 5 world renders?
    cams[i]->Hide();
    buffs[i]->Disable();
    }
    
    context->Enable();
    //draw each buffer
    for (int i = 0; i < numViews; i++){
    context->DrawImage(buffs[i]->GetColorTexture(), i*context->GetWidth()/numViews, 0);
    context->DrawLine(i*context->GetWidth() / numViews, 0, i*context->GetWidth() / numViews, context->GetHeight());
    }
    context->Sync();
    return true;
    }
    

     

    thank's in advance

     

    jio

  2. 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 :(

  3. 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

  4. 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

  5. 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:

    mouse%20outside.png

     

    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

    mouse%20over.png

     

     

    mouse%20click.png

     

     

    thank's in advance

     

    jio

  6. 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

  7. 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 :)

  8. 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()

     

    http://www.leadwerks.com/werkspace/topic/10381-requested-features-and-improvements/page__st__40#entry76787

     

    but seems to not exists.

     

    any help is appreciated!

     

    thank's in advance

     

    jio

  9. 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

    • Upvote 1
  10. 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

  11. 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

  12. 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

  13. 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;
    }
    

  14. @shadoh

     

    *It's useful to search the map for key entities all at one time so you can reference them later. Example: Spawn Points, HeightMap

    I 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")+"/");

    • Upvote 1
  15. 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);
    }
    

  16. 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.

  17. 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

×
×
  • Create New...