Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the size of the OpenGL window in Android

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


2 Answers

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

like image 192
GrkEngineer Avatar answered Nov 29 '25 15:11

GrkEngineer


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

like image 32
laginimaineb Avatar answered Nov 29 '25 17:11

laginimaineb