Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: White Screen on OpenGL Sample

Just to respond to both of you, I did some testing with my own code (which works 100% on Sim and Device) and the code provided by RIM (http://docs.blackberry.com/en/developers/deliverables/11942/CS_OpenGLTest_952941_11.jsp) and the only change is the namespace (I have it in a little collective-sample project).

 

So I am completely baffeled as to why it works for me and not for you.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Contributor
sahnawaj
Posts: 8
Registered: ‎09-22-2010
My Device: Not Specified

Re: White Screen on OpenGL Sample

Hi rcmaniac25 ,

 

Is it because of some kind of system Hardware configuration(i.e.. Graphics Card) or may be we have to install some driver.

 

can u pls. give me a brief idea of your system configurations.

 

thanks

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: White Screen on OpenGL Sample

Right now:

Win7 x64 Pro

Core i7 Quad (1.73GHz)

4GB Mem

Nvidia Quadro FX 880M 1GB dedicated memory

 

In the past (also working):

Win Vista x32 Ultimate

Pentium M 1.5GHz

4GB Mem

Some old ATI intergrated card with 32MB dedicated memory

 

Personally I don't think it is a hardware element but it could be a driver, RIM has stated in the past the the graphics, video, and sound processing/encoding support on the Sims are based off what codecs and drivers you have installed on your computer.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Contributor
sahnawaj
Posts: 8
Registered: ‎09-22-2010
My Device: Not Specified

Re: White Screen on OpenGL Sample

hi,

 

do you have any idea what codecs and drivers i  have to installed on my computer.

 

 

Thanks 

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: White Screen on OpenGL Sample

I can't really help you there, what are you running?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
hakimrie
Posts: 82
Registered: ‎07-23-2009
My Device: 9900

Re: White Screen on OpenGL Sample

I find same problem, simulator (9550) return true when I test with 

 

GLUtils.isSupported();

 

 

but still, it can't display anything (blank screen) when I run blackberry opengl sample code.

and after i look rcmaniac25 spec, may be the problem is in graphic card, I use laptop with integrated (not dedicated) graphic card.

 

my laptop processor is intel core i5 , (so) the graphic card is integrated/internal Intel Graphics Media Accelerator HD (core i5).

 

I still not sure why it happen, I think RIM should do something to make it work in a laptop/pc with dedicated memory.

 

btw, my laptop can render opengl in Android emulator.

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: White Screen on OpenGL Sample

The sim uses the graphics that you have.

 

Here is the code I have:

 

import java.nio.*;

import javax.microedition.khronos.egl.*;
import javax.microedition.khronos.opengles.*;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.opengles.*;

/**
 * Rendering a multi color 2-D triangle.
 */
public class RIM2DTri extends FullScreen implements Runnable
{
	private EGL11 _egl;
    private EGLDisplay _eglDisplay;
    private EGLConfig _eglConfig;
    private EGLSurface _eglSurface;
    private EGLContext _eglContext;
    private GL10 _gl;

    private Bitmap _offscreenBitmap;
    private Graphics _offscreenGraphics;

    private FloatBuffer _vertexArray;
    private FloatBuffer _colorArray;

    private boolean _running;
    private boolean _paused;

    public RIM2DTri()
    {
        super(FullScreen.DEFAULT_MENU | FullScreen.DEFAULT_CLOSE);
    }

    private void initialize()
    {
        // Get EGL interface
        _egl = (EGL11)EGLContext.getEGL();

        // Get the EGL display
        _eglDisplay = _egl.eglGetDisplay(EGL11.EGL_DEFAULT_DISPLAY);

        // Initialize the display for EGL, null since we don't really need the version
        _egl.eglInitialize(_eglDisplay, null);

        // Choose an EGL config
        EGLConfig[] configs = new EGLConfig[1];
        int[] numConfigs = new int[1];
        int[] attrs =
        {
            EGL11.EGL_RED_SIZE,   5,
            EGL11.EGL_GREEN_SIZE, 6,
            EGL11.EGL_BLUE_SIZE,  5,
            EGL11.EGL_NONE
        };
        _egl.eglChooseConfig(_eglDisplay, attrs, configs, 1, numConfigs);
        _eglConfig = configs[0];

        // Create an EGL window surface
        _eglSurface = _egl.eglCreateWindowSurface(_eglDisplay, _eglConfig, this, null);

        // Create an EGL context
        createEGLContext();

        // Specify vertices and colors for a triangle
        float[] vertices =
        {
            -0.5f, -0.5f, 0.0f,
            0.0f, 0.5f, 0.0f,
            0.5f, -0.5f, 0.0f
        };
        float[] colors =
        {
            0.0f, 1.0f, 0.0f, 1.0f,
            1.0f, 0.0f, 0.0f, 1.0f,
            0.0f, 0.0f, 1.0f, 1.0f
        };
        _vertexArray = ByteBuffer.allocateDirect(3 * 3 * 4).asFloatBuffer();
        _vertexArray.put(vertices);
        _vertexArray.rewind();
        _colorArray = ByteBuffer.allocateDirect(4 * 3 * 4).asFloatBuffer();
        _colorArray.put(colors);
        _colorArray.rewind();
    }

    private void createEGLContext()
    {
        // Create an EGL context
        _eglContext = _egl.eglCreateContext(_eglDisplay, _eglConfig, EGL10.EGL_NO_CONTEXT, null);

        // Get the GL interface for our new context
        _gl = (GL10)_eglContext.getGL();

        // Make our new context current
        _egl.eglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext);
    }

    private void destroyEGL()
    {
        _egl.eglMakeCurrent(_eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        _egl.eglDestroyContext(_eglDisplay, _eglContext);
        _egl.eglDestroySurface(_eglDisplay, _eglSurface);
    }

    private void handleContextLost()
    {
        // Destroy our EGL context
        _egl.eglMakeCurrent(_eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        _egl.eglDestroyContext(_eglDisplay, _eglContext);
        _eglContext = EGL10.EGL_NO_CONTEXT;

        // Re-create our EGL context
        createEGLContext();
    }

    /**
     * Main render loop.
     */
    public void run()
    {
        initialize();

        while (_running)
        {
            // Idle If we are in the background
            if (_paused)
            {
                synchronized (this)
                {
                    try
                    {
                        wait();
                    }
                    catch (InterruptedException x) { }
                }
            }

            updateBackBuffer();

            renderFrame();

            // Throttle cpu usage
            try
            {
                Thread.sleep(20);
            }
            catch (InterruptedException x) { }
        }

        destroyEGL();
    }

    private void renderFrame()
    {
        // Make our context and surface current and check for EGL_CONTEXT_LOST
        if (!_egl.eglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext))
        {
            if (_egl.eglGetError() == EGL11.EGL_CONTEXT_LOST)
            {
                handleContextLost();
            }
        }

        // Signal that we are about to begin OpenGL rendering
        _egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, _offscreenGraphics);

        render(_gl);

        // Signal that OpenGL ES rendering is complete
        _egl.eglWaitGL();

        // Swap the window surface to the display
        _egl.eglSwapBuffers(_eglDisplay, _eglSurface);
    }

    private void render(GL10 gl)
    {
        // Set our GL viewport
        gl.glViewport(0, 0, getWidth(), getHeight());
        
        // Clear the surface
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        
        // Set our projection matrix
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        GLUtils.gluPerspective(gl, 45.0f, (float)getWidth()/(float)getHeight(), 0.15f, 10.0f);
        
        // Draw our triangle
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, 0.0f, -3.0f);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexArray);
        gl.glColorPointer(4, GL10.GL_FLOAT, 0, _colorArray);
        gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
    }

    /**
     * Called by the UI system to paint the screen.
     */
    protected void paint(Graphics g)
    {
        if (_offscreenBitmap != null)
        {
            g.drawBitmap(0, 0, _offscreenBitmap.getWidth(), _offscreenBitmap.getHeight(), _offscreenBitmap, 0, 0);
        }
    }

    /**
     * Called when the visibility of our screen changes.
     *
     * @param visible true if our screen is being made visible,
     * false if it's being hidden
     */
    protected void onVisibilityChange(boolean visible)
    {
        if (visible)
        {
            resume();
        }
        else
        {
            pause();
        }
    }

    /**
     * Called when the screen is closing.
     */
    public void close()
    {
        _running = false;
        synchronized (this) { notifyAll(); }

        super.close();
    }

    /**
     * Keeps the back buffer in sync with the screen size.
     */
    private void updateBackBuffer()
    {
        if (_offscreenBitmap != null)
        {
            if (_offscreenBitmap.getWidth() == getWidth() && _offscreenBitmap.getHeight() == getHeight())
            {
                return; // no change needed
            }
        }

        _offscreenBitmap = new Bitmap(getWidth(), getHeight());
        _offscreenGraphics = Graphics.create(_offscreenBitmap);
    }

    private void pause()
    {
        _paused = true;
    }

    private void resume()
    {
        if (_running)
        {
            // Pause the render loop
            _paused = false;
            synchronized (this) { notifyAll(); }
        }
        else
        {
            // Start the render thread.
            _running = true;
            new Thread(this).start();
        }
    }
}

 

This works on simulator and on device. If it doesn't work for you then I have no clue.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
hakimrie
Posts: 82
Registered: ‎07-23-2009
My Device: 9900

Re: White Screen on OpenGL Sample

hi rcmaniac25, thanks for your code :smileyhappy:

 

unfortunately, it is still not work ;

I think because I can't turn off hardware accelerator in my laptop;

 

I use windows 7 home premium, and the hardware accelerator setting can't be changed. :smileysad:

 

I don't understand why in order to run Opengl in Blackberry simulator must disable hardware accelerator; because it is OK in android simulator.  :smileysad:

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: White Screen on OpenGL Sample

Try disabling graphics acceleration. It should be a simulator option, not a system option.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
hakimrie
Posts: 82
Registered: ‎07-23-2009
My Device: 9900

Re: White Screen on OpenGL Sample

Still not work, only display white screen and turn to black when I click-touch the screen