×

Discussion Board

Results 1 to 7 of 7

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    52

    is it possible to mix bitmap graphics with OpenGL ES?

    Hi,
    I am just wondering if it is possible to create a game that uses both standard Symbian bitmap graphics as well as OpenGL ES.

    Basically I want to have a bitmap image as the "ground" with a number of 3d objects on it. I want to use a bitmap as the ground instead of a standard texture because I want to use the GetPixel method to determine if a player is on a track ( a black section of the bitmap).

    Is this possible?

    Thanks in advance,
    Miranda

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    68
    Hi.

    I assume that you want to do picking? If you need to pick only one pixel, you can do all the rendering in GL side and just replace GetPixel( ) with glReadPixels limited to a one pixel. If you want to check multiple pixels, then you need to read bigger area.

    If you really want to mix GL and native rendering you have at least 3 choices:

    1. feed the bitmap as a texture to OpenGL ES, render with GL, call readpixels to get GL framebuffer back into bitmap, render bitmap stuff again, feed the bitmap as texture back to OpenGL ES, ...

    2. use pixmap render surface, use eglWaitGL( ) and eglWaitNative( ) to synchronize rendering

    3. use pbuffer and eglCopyBuffers( ) + feed the bitmap in as a texture

    Choice (1) is guaranteed to work across all implementations, but it involves 2 copies for a full trip (copy of bitmap to texture, reading of framebuffer to a bitmap).

    Choice (2) may not be supported everywhere as pixmap surface support is optional in EGL. For SW implementations this is the fastest way as the bitmap IS the render target -> there is no copying between GL and bitmap based stuff.

    Choice (3) should work, but it comes with the same hit as the choice (1) (eglCopyBuffers will cause a copy and loading in a texture will cause a copy)



    Jani Vaarala
    Graphics Architect
    Nokia

  3. #3
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    52
    I want to use it as a kind of collision detection for a series 60 game. I don't have a preference for how I do it.

    Basically the pseudocode for the main game loop is:
    Code:
    bool movable;
    pixel color;
    
    color = getPixel(currX, currZ); //or however this should be done
    
    if (color == black)
        movable = true;
    else
        movable = false;
    
    if (movable)
       //player can move
    How do you suggest I should do this?
    Thanks,
    Miranda

  4. #4
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    68
    Could you try the example code below:

    Code:
    bool movable;
    TUint8 pixelColor[4];
    
    glReadPixels( currX, currY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixelColor[0]);
    
    if(pixelColor[0] == 0 &&
       pixelColor[1] == 0 &&
       pixelColor[2] == 0)
        movable = true;
    else
        movable = false;
    
    if (movable)
       //player can move
    Also, read the documentation glReadPixels( ) from the OpenGL ES spec, as the X and Y are not in the same way as you expect from standard 2D graphics.

    Jani Vaarala
    Graphics Architect
    Nokia

  5. #5
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    52
    thanks, I had some very similar code that wasn't working, so I'll try your version.
    My code was:
    Code:
    TRgb CGame01::getColour(TReal x, TReal y) {
    
        TInt r, g, b, a;
        GLuint aPixel;
        TRgb pixel_colour;
        glReadPixels( x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &aPixel );
    
        r = aPixel >> 0; // get the red value of the pixel
        g = aPixel >> 8;
        b = aPixel >> 16;
        a = aPixel >> 24;
    
        pixel_colour = TRgb(r, g, b);
    
        return pixel_colour;
    }
    And I was having troubles extracting the individual rgb values, so your version looks better.

    The only problem I see is that the player is moving along x and z, whereas you (and other code i have seen) asks for x and y. Is it possible to use the z value?
    Last edited by miranda2112; 2005-04-06 at 03:47.

  6. #6
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    52
    YAY! It seems to be working!!!

    Now I just have to sort out my warped textures....

  7. #7
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    68
    Hi.

    Good that you got it working. Reading of Z is not directly possible, but you can use some extremely slow (effectively useless, don't blame me if it runs 0.001fps on graphics HW :-) techniques to find out the depth.

    One way to do it:

    Code:
    color <- readpixels from x, y
    testcolor <- some modification to the color
    
    for Z in depth from back -> front
         draw one pixel at x,y with depth Z and color "testcolor"
         color2 <- readpixels from x,y
         if color2 != color -> break
    
    // when the for loop exists, Z equals to the depth value that was stored in the buffer
    Of course if you only need rough depth (for example if it is 0, 0.25, 0.5, 0.75, or 1.0), you can increase the step in the for loop.

    Jani Vaarala
    Graphics Architect
    Nokia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •