views:

733

answers:

2

Hi, I'm trying to draw a square in OpenGL ES (Android), 2D and covering the whole screen.

At the moment I'm just using trial and error but am sure there has got to be a better way to get the size of the screen. Below is how I'm currently initializing square:

    float[] square = new float[] {  -0.1f, -0.1f, 0.0f,
        0.1f, -0.1f, 0.0f,
        -0.1f, 0.1f, 0.0f,
        0.1f, 0.1f, 0.0f };

Ideally the 0.1f in the x axis would be be the width and 0.1 in y the height of the window. Any help would be greatly appreciated.

Cheers

A: 
. . .
    WindowManager w = getWindowManager();
    Display d = w.getDefaultDisplay();
    int width = d.getWidth();
    int height = d.getHeight();
. . .

see http://groups.google.com/group/android-developers/browse_thread/thread/229c677ef0c5ae97

laginimaineb
that gives the pixel resolution, I'm looking for the size in relation to the openGL viewport.
+1  A: 

I think the size of the screen depends on your projection. For 2D graphics, most people use glOrtho to define the parallel projection. It's up to you to specify the size here.

Also, you can specify a larger size and have multiple 2D textures positioned within the clipping bounds, or you can have a single texture with the vertices mapped to the corners of your specified projection. This single texture would contain your entire display contents.

The following site explains this a little better. http://www.scottlu.com/2008/04/fast-2d-graphics-wopengl-es.html

GrkEngineer