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
Contributor
reet
Posts: 25
Registered: ‎03-29-2011
My Device: 9000 BOLD

how to start opengl application development

hello

 

i m new developer on blackberry application development

i had installed jdk 6 and Blackberry java plugin for Eclipse v 1.3 (installer) from blackberry site

http://us.blackberry.com/developers/javaappdev/devtools.jsp

 

then a workspace is opened i.e. Eclipse Helios with the name Blackberry application development.

It also has blackberry option in that.

Then i start creating a project

File -> New-> other ->blackberry project

 

Then a new window named "New blackberry Project" is opened

 I give "Blackberry" as project name then next

came java settings window .. nothing changed in that then next

in template window choose "blackberry application " then next

here comes application details.. i entered these..

 

Package name-                org.opengl.com

Application Class name-  OpenGLTest

screen Class name-        OpenGLTestScreen

Screen title-                      OPEN

 

then click finish

 

In Blackberry_application_descriptor.xml file

i added Title as "TRIANGLE"  no other changes

 

and i copied the following code in OpenGLTest.java file

 

package org.opengl.com;

import net.rim.device.api.ui.UiApplication;


public final class OpenGLTest extends UiApplication
{
    public OpenGLTest()
    {
        pushScreen(new OpenGLTestScreen());
    }

    public static void main(String[] args)
    {
        new OpenGLTest().enterEventDispatcher();
    }
}

 

and in OpenGLTestScreen.java file ... the following one

 

package org.opengl.com;

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.*;


class OpenGLTestScreen 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;

    OpenGLTestScreen()
    {
        super(FullScreen.DEFAULT_MENU | FullScreen.DEFAULT_CLOSE);
    }

    private void initialize()
    {
     
     System.out.println("start initialise ");
        // Get EGL interface
        _egl = (EGL11)EGLContext.getEGL();

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

        // Initialize the display for EGL setting the version to null
        _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 the new context
        _gl = (GL10)_eglContext.getGL();

        // Make the 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 the 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 the EGL context
        createEGLContext();
    }

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

        while (_running)
        {
            // Idle if this thread is 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 the 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 OpenGL rendering is about to begin
        _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 the 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 the projection matrix
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        GLUtils.gluPerspective
            (gl, 45.0f, (float)getWidth()/(float)getHeight(), 0.15f, 10.0f);

        // Draw the 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 the screen changes.
     *
     * @param visible true if the screen is being made visible,
     * false if 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();
        }
    }
}

 

 

 

 

Now on running this project by

run as blackberry simulator which 9800 available with plugin

 

here come the screen as

 

 

JVM error 104

Uncaught:  IlegalArgument exception

scrol for available commands

continue..

 

on clicking continue nothing comes and on clicking on application icon named as "TRIANGLE" in simulator menu

here comes the white screen...  i don't knw what's the problem?

please help me in this application

i had copied this code from blackberry site.. its

Code sample: Rendering a multicolor 2-D triangle

 

please help

 

regards Reet

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: how to start opengl application development

[ Edited ]

I haven't looked at your code because something else caught my eye. You said you were testing on the 9800? That doesn't support OpenGL.

 

Currently only CDMA phones support OpenGL. The only 6.0 CDMA phone (I can find) is the Style 9670.

 

If you require a touchscreen device with OpenGL then you have to look at the Storm2 9550 which only goes up to 5.0 right now.

 

Note: BlackBerry's that end in XX30, XX50, XX70 are CDMA. BlackBerry's with OpenGL support:

http://supportforums.blackberry.com/t5/Java-Development/BlackBerry-Smartphones-that-support-OpenGL-E...

---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.
Contributor
reet
Posts: 25
Registered: ‎03-29-2011
My Device: 9000 BOLD

Re: how to start opengl application development

hello rcmaniac25

 

 i tried with simulator 9550, 8530, 9650

But it still giving the same result. The white screen :-(

please help

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: how to start opengl application development

[ Edited ]

Hmm, It seems you are encountering a fairly common issue people keep coming up with.

 

Do a search for "white screen opengl" and see if any of those fix the problem. If not I will see what I can do. One of the results should have some code that works for me on the simulator and actual device.

 

Edit: Noticed you had already posted in one of them. Have you looked at any others?

---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.
Contributor
reet
Posts: 25
Registered: ‎03-29-2011
My Device: 9000 BOLD

Re: how to start opengl application development

 

i tried a lot.. checked many times all the posts and lots of search on google about white screen problem but that to no avial. :smileysad:

 

i checked about installation a lot that it confused me now that what actually should be done with this.

Is this white screen problem is bcoz of configuration or simulator problem or anything else.

 

The plugin on which i m working now is Blackberry JDE plugin full 1.1.2

 with blackberry JDE 4.7 and java jdk 6 . these two were installed before plugin.

 

is this way is correct??

 

i had tried with Blackberry JDE plugin full 1.3.0 also but no help.

 

reet

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: how to start opengl application development

Do you have the 5.0 and/or 6.0 component pack installed and set for use in the project you are working on? 4.7 doesn't support OpenGL.

---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.
Contributor
reet
Posts: 25
Registered: ‎03-29-2011
My Device: 9000 BOLD

Re: how to start opengl application development

earlier i was having 4.7 blackberry JDE now i installed blackberry JDE 6.0 but still its not working.

and what's the meaning of this component pack?

 

reet

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: how to start opengl application development

What's the meaning of "this" component pack? Component packs correspond to OS versions. OpenGL was added in OS 5.0 and updated in 6.0. Component pack 5.0 and 6.0 have OpenGL support.

---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.
Contributor
reet
Posts: 25
Registered: ‎03-29-2011
My Device: 9000 BOLD

Re: how to start opengl application development

sorry

 

I got confused now with component pack.

I m using windows 7 professional and its showing version as 6.1

 

and i hav installed Blackberry JDE 4.7 and 6.0

 

now please tell me which component pack i have??

 

regards

reet

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: how to start opengl application development

I'm still a bit confused myself. JDE and component pack are two different things.

 

Do you use Eclipse when developing for BlackBerry?

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