[Solved] Texture rendering in osg

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

mola
Just popping in
Just popping in
Posts: 5
Joined: Thu Feb 12, 2015 22:42

[Solved] Texture rendering in osg

Postby mola » Thu Feb 12, 2015 22:55

hello

i want to draw chart on cegui window .
i have sample code to draw chart on osg hud .
Image


http://molaora.ir/wp-content/uploads/2015/02/test_cegui.tar.gz

i want to draw it on cegui::window or image.
or can i draw direct to cegui::texture ?

i write this code too :
i create a button on click i want to see texture with random color but only white image load , why :hammer: ?

Code: Select all

//    CEGUI::System& ceguiSystem = CEGUI::System::getSingleton();

    CEGUI::Sizef size(static_cast<float>(256.0), static_cast<float>(256.0));

//    CEGUI::TextureTarget* renderTextureTarget = CEGUI::System::getSingletonPtr()->getRenderer()->createTextureTarget();
//    renderTextureTarget->declareRenderSize(size);

//    CEGUI::GUIContext& renderGuiContext = ceguiSystem.createGUIContext(static_cast<CEGUI::RenderTarget&>(*renderTextureTarget) );

    // We create a CEGUI Texture using the renderer you use:
    CEGUI::Texture& texture = CEGUI::System::getSingletonPtr()->getRenderer()->createTexture("MyCEGUITextureName",size);

    CEGUI::Rectf imageArea;
    imageArea= CEGUI::Rectf(0.0f, 0.0f, 256, 256);

    CEGUI::OpenGLTexture& rendererTexture = static_cast<CEGUI::OpenGLTexture&>(texture);

    unsigned char data[ (256*256)*4 ];
    for (int i =0; i<((256*256)*4); i++)
        data[i] = (rand()/ (RAND_MAX*1.0) )*255;

    rendererTexture.blitFromMemory(data, imageArea);
    // We create a BasicImage and set the Texture
    CEGUI::BasicImage* image = static_cast<CEGUI::BasicImage*>(&CEGUI::ImageManager::getSingleton().create("BasicImage", "aoscope/aoscope1"));
    image ->setTexture(&rendererTexture);

        imageArea= CEGUI::Rectf(0.0f, 0.0f, 256, 256);

    image->setArea(imageArea);
    image->setAutoScaled(CEGUI::ASM_Disabled);

    CEGUI::Window* bfft = (CEGUI::Window*)d_root->getChild("AScope");

    CEGUI::Window* fft = (CEGUI::Window*)d_root->getChild("AScope/StaticImage");
    fft->setProperty("Image", "aoscope/aoscope1");


    fft->invalidate();
    bfft->invalidate();

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Texture rendering in osg

Postby Ident » Fri Feb 13, 2015 10:13

Is it relevant that it is OSG in any way? I don't see the OSG-specificness. Also I think this should go into General Help, not Advanced help. I will move it.

Have you looked at this? http://cegui.org.uk/wiki/index.php?title=Rendering_to_texture_(RTT)_in_CEGUI
I wrote this a while ago and it helped quite a few people.

I see you did most of the things suggested there. Did you try to directly render the texture you created (without CEGUI) and see if it displays correctly?
CrazyEddie: "I don't like GUIs"

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Texture rendering in osg

Postby dermont » Fri Feb 13, 2015 11:21

mola wrote:.. i want to see texture with random color but only white image load , why :hammer: ?


I don't the answer to your question, could be your data array, some static cast missing on your Vector2. However I had exactly the same problem as you with blitFromMemory trying to load a GStreamer video texture on OpenGL (CEGUI 0.8 I think).

In the end I had to create my own texture and manually update. I don't remember what the problem was (pixel formats) or maybe I just did the same way as you.

Anway looking at my old video texture on 0.8.4 and your code it appears to work here. Maybe you could try the following code with your parent window. The data is just the OpenGl checker example.

Code: Select all

void createTexture(CEGUI::Window *parent)
{
     int width  = 256;
     int height = 256;
       
     CEGUI::Sizef size(static_cast<float>(width), static_cast<float>(height));

     CEGUI::OpenGLRenderer* rs = static_cast<CEGUI::OpenGLRenderer*>(
                    CEGUI::System::getSingleton().getRenderer());

     CEGUI::Texture* texture = &rs->createTexture("Checked",size);

     CEGUI::Rectf imageArea(0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height));

     int i, j, c;
     unsigned char data[256][256][4];

     for (i = 0; i < 256; i++) {
        for (j = 0; j < 256; j++) {
             c = ((((i&0x8)==0)^((j&0x8))==0))*255;
             data[i][j][0] = (GLubyte) c;
             data[i][j][1] = (GLubyte) c;
             data[i][j][2] = (GLubyte) c;
             data[i][j][3] = (GLubyte) 255;
        }
      }

      texture->blitFromMemory(&data[0], imageArea);
      // We create a BasicImage and set the Texture
      CEGUI::BasicImage* image = static_cast<CEGUI::BasicImage*>(&CEGUI::ImageManager::getSingleton().create("BasicImage", "Checked"));
      image ->setTexture(texture);

      image->setArea(imageArea);
      image->setAutoScaled(CEGUI::ASM_Disabled);

      CEGUI::Window* vImage = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "StatImage");
      vImage->setSize(CEGUI::USize(CEGUI::UDim(static_cast<float>(width), 0)     , CEGUI::UDim(static_cast<float>(height), 0)));
      vImage->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0.0), CEGUI::UDim(0, 0.0f)));

      vImage->setProperty("Image", texture->getName());
      parent->addChild(vImage);
}

mola
Just popping in
Just popping in
Posts: 5
Joined: Thu Feb 12, 2015 22:42

Re: Texture rendering in osg

Postby mola » Fri Feb 13, 2015 12:12

thanks for answer

i run your code but image is white too.
what's wrong ?

Image

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Texture rendering in osg

Postby Ident » Fri Feb 13, 2015 15:54

Can you use gldebugger or anything like it and check if the texture itself is correct? What happens if you just render the texture directly`?
CrazyEddie: "I don't like GUIs"

mola
Just popping in
Just popping in
Posts: 5
Joined: Thu Feb 12, 2015 22:42

Re: Texture rendering in osg

Postby mola » Tue Feb 17, 2015 13:21

hello,

in this function GL_MAX_TEXTURE_SIZE return zero
and cegui error is "size too big" for textur and no texture created.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Texture rendering in osg

Postby Ident » Tue Feb 17, 2015 13:25

I asked two times already, I will try one last time: What happens if you render the texture directly
Is the graph you show below the FrameWindow the texture that is supposed to be inside the FrameWindow? Is that the identical texture? Yes or no?
And if no, did you try to render the texture directly that you supply to CEGUI and how was it rendered then?


Also what is the texture size and why did you not tell us before that there is an error.

We are getting closer to the solution...
CrazyEddie: "I don't like GUIs"

mola
Just popping in
Just popping in
Posts: 5
Joined: Thu Feb 12, 2015 22:42

Re: Texture rendering in osg

Postby mola » Tue Feb 17, 2015 14:13

I found the bug,
when run osg in multithread doesn't work but if run in singlemode it'srun OK,

mola
Just popping in
Just popping in
Posts: 5
Joined: Thu Feb 12, 2015 22:42

Re: [Solved] Texture rendering in osg

Postby mola » Thu Feb 19, 2015 06:40

hi again,
when i click button the texture update and show when use timer to update image not update in UI.

Code: Select all

    CEGUI::Texture* texture;
    CEGUI::OpenGLRenderer* rs = static_cast<CEGUI::OpenGLRenderer*>(
                   CEGUI::System::getSingleton().getRenderer());

    texture = &rs->getTexture("RRTaoscope");

    CEGUI::Rectf imageArea(0.0f, 0.0f, static_cast<float>(256), static_cast<float>(256));

    int i, j, c;

    for (i = 0; i < 256; i++) {
       for (j = 0; j < 256; j++) {
            c =  ((((i&0x8)==0)^((j&0x8))==0))*255;
            chartOscope[i][j][0] = (GLubyte) c;
            chartOscope[i][j][1] = (GLubyte) c;
            chartOscope[i][j][2] = (GLubyte) c;
            chartOscope[i][j][3] = (GLubyte) 255;
       }
     }
    texture->blitFromMemory(&chartOscope[0], imageArea);

    CEGUI::Window* fft = (CEGUI::Window*)d_root->getChild("FFTScope/StaticImage");
    fft->invalidate();

    CEGUI::Window* ff = (CEGUI::Window*)d_root->getChild("FFTScope");
    ff->invalidate();


User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: [Solved] Texture rendering in osg

Postby Ident » Thu Feb 19, 2015 18:50

Based on your sentence it is really hard to understand what you are trying to tell us, even after looking at the code. Could you please express yourself in correct English? For now I do not understand what is going on.
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 20 guests