Directly draw on an Image or Texture from the code?

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

blablub
Not too shy to talk
Not too shy to talk
Posts: 28
Joined: Tue Mar 01, 2011 11:56

Directly draw on an Image or Texture from the code?

Postby blablub » Mon Apr 18, 2011 15:28

Hi,

ist it possible to directly "draw" on an image/texture from the code? For example on a StaticImage. Like directly accessing the pixels and setting their colors?

What I'm looking for is something like this (pseudo code):
- StaticImage::draw(int x, int y, colour c)
- Texture::draw(int x, int y, colour c)

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Directly draw on an Image or Texture from the code?

Postby Kulik » Mon Apr 18, 2011 16:07

you can blit in CEGUI 0.8 but not in 0.7 I am afraid. You can use the tools that the renderer gives you though, if you use OpenGL just get the texture id and blit to that.

blablub
Not too shy to talk
Not too shy to talk
Posts: 28
Joined: Tue Mar 01, 2011 11:56

Re: Directly draw on an Image or Texture from the code?

Postby blablub » Mon Apr 18, 2011 16:45

Thanks for the reply.

I use Ogre. The reason why I want this, is I already have some kind of 2x2 array full of some complex objects. And I wanted to map this to a pixel picture where each array[i][j] corresponds to a pixel[i][j]. This way I could easily create a colored nice-to-read chart of the array.

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

Re: Directly draw on an Image or Texture from the code?

Postby dermont » Thu Apr 21, 2011 16:21

Kulik wrote:you can blit in CEGUI 0.8 but not in 0.7 I am afraid. You can use the tools that the renderer gives you though, if you use OpenGL just get the texture id and blit to that.


Do you have an example of how to use blit with CEGUI 0.8, I'm not too sure how to make it work properly.

This is my code for creating the texture/static image:

Code: Select all

    // texture
    CEGUI::Texture &guiTex = myRenderer.createTexture("RTTITexture", 103, CEGUI::Sizef(720, 480) );
    const CEGUI::Rectf rect(CEGUI::Vector2f(0.0f, 0.0f), guiTex.getOriginalDataSize());

    // video
    mCEGUIVideoGST = new CEGUIVideoGST("TestVideo",&guiTex);

    // image
    const CEGUI::String name = "RTTImage";
    CEGUI::BasicImage image(name, &guiTex, rect,
                     CEGUI::Vector2f(0, 0), false, CEGUI::Sizef(0, 0));
    CEGUI::ImageManager::getSingleton().add(image);

    // static image
    CEGUI::Window *si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "RTTWindow");
    si->setSize(CEGUI::UVector2(CEGUI::UDim(0.6f, 0),
                                CEGUI::UDim(0.6f, 0)));
    si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.2f, 0.2),
                                    CEGUI::UDim(0.2f, 0.2f)));
    si->setProperty("Image", "RTTImage");
    sheet->addChild(si);


This is my code for rendering a GStreamer video to the texture (CEGUI static image). The OpenGL code works fine but the blitFromMemory doesn't; are there other steps that I'm missing?

Code: Select all

CEGUIVideoGST(CEGUI::String _videoname, CEGUI::Texture* videoTex) :
        mVideoTexture(videoTex)
{
    ...
    void update()
    {
       ...
        OpenGLTexture* ogl_texture = static_cast<OpenGLTexture*>(mVideoTexture);

        if (mVideoInfo.textureDirty)
             ogl_texture->setTextureSize(CEGUI::Sizef(mVideoInfo.width, mVideoInfo.height));

        //const CEGUI::Rectf area(CEGUI::Vector2f(0.0f, 0.0f), CEGUI::Vector2f(mVideoInfo.width, mVideoInfo.height));
        //ogl_texture->blitFromMemory(&GST_BUFFER_DATA(buffer)[0], area);
         
        glBindTexture (GL_TEXTURE_2D, ogl_texture->getOpenGLTexture());
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

        glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0,
                  mVideoInfo.width, mVideoInfo.height,
                  GL_RGBA, GL_UNSIGNED_BYTE, GST_BUFFER_DATA (buffer));
        ...

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Directly draw on an Image or Texture from the code?

Postby Kulik » Thu Apr 21, 2011 17:11

EDIT: This looks fishy to me:

Code: Select all

&GST_BUFFER_DATA(buffer)[0]

GST_BUFFER_DATA(buffer) doesn't work?

The blitting code does pretty much the same thing you do so I am puzzled why this doesn't work :-/ You maybe could check what it does under different renderers.

Code: Select all

//----------------------------------------------------------------------------//
void OpenGLTexture::blitFromMemory(void* sourceData, const Rectf& area)
{
    // save old texture binding
    GLuint old_tex;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex));

    // set texture to required size
    glBindTexture(GL_TEXTURE_2D, d_ogltexture);
   
    glTexSubImage2D(GL_TEXTURE_2D, 0,
        area.left(), area.top(),
        area.getWidth(), area.getHeight(),
        GL_RGBA8, GL_UNSIGNED_BYTE, sourceData
    );

    // restore previous texture binding.
    glBindTexture(GL_TEXTURE_2D, old_tex);
}


It's also possible that the blitting code is flawed, it's quite new and I only tested under Windows but I think CrazyEddie tested this under Linux so it should be OK.

You might want to check how I blit in the Chrome integration contrib module - http://crayzedsgui.hg.sourceforge.net/h ... t.cpp#l315
(warning: I haven't touched this in 3 months so it likely won't compile but it should be easy to fix, it's CEGUI 0.8 only)

offtopic: You are playing with some seriously cool stuff there. Would you mind sharing the code when it's done? I planned to make a gstreamer CEGUI integration contrib module as well but didn't due to time constraints.

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

Re: Directly draw on an Image or Texture from the code?

Postby dermont » Fri Apr 22, 2011 17:14

Kulik wrote:You might want to check how I blit in the Chrome integration contrib module - http://crayzedsgui.hg.sourceforge.net/h ... t.cpp#l315
(warning: I haven't touched this in 3 months so it likely won't compile but it should be easy to fix, it's CEGUI 0.8 only)


Thanks I'll check out the link provided.

Kulik wrote:EDIT: This looks fishy to me:

Code: Select all

&GST_BUFFER_DATA(buffer)[0]

GST_BUFFER_DATA(buffer) doesn't work?

The blitting code does pretty much the same thing you do so I am puzzled why this doesn't work :-/ You maybe could check what it does under different renderers.


I tried to isolate the problem as before, it appears the problem is related to the pixel data format GL_RGBA works fine( GL_RGBA8 doesn't) though the buffer data format is guint8.

Code: Select all

    //----------------------------------------------------------------------------//
    void MyblitFromMemory(void* sourceData, const Rectf& area)
    {
        OpenGLTexture* ogl_texture = static_cast<OpenGLTexture*>(mVideoTexture);
        glBindTexture(GL_TEXTURE_2D, ogl_texture->getOpenGLTexture());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812F); // GL_CLAMP_TO_EDGE
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 0x812F); // GL_CLAMP_TO_EDGE
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
       
        glTexSubImage2D(GL_TEXTURE_2D, 0,
            area.left(), area.top(),
            area.getWidth(), area.getHeight(),
            GL_RGBA, GL_UNSIGNED_BYTE, sourceData
        );
    }

     const CEGUI::Rectf area(CEGUI::Vector2f(0.0f, 0.0f), CEGUI::Vector2f(mVideoInfo.width, mVideoInfo.height));
     MyblitFromMemory(&GST_BUFFER_DATA(buffer)[0], area);



Kulik wrote:offtopic: You are playing with some seriously cool stuff there. Would you mind sharing the code when it's done? I planned to make a gstreamer CEGUI integration contrib module as well but didn't due to time constraints.


Most of the credit should go to hpesoj and his fine contribution here:
http://www.ogre3d.org/tikiwiki/Using+GS ... e=Cookbook

I'll try and update the code to work with CEGUI gtk/Ogre if I find the time, you are welcome to the code whenever.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 27 guests