Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 11

Thread: Drawing objects as per screen coords in OpenGL-ES 2.0

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    39

    Drawing objects as per screen coords in OpenGL-ES 2.0

    Hi,

    I have a 2D map that I have created in OpenGL-ES 2.0. I'd like to add a scalebar.

    As this will not be moved when the user pans the map, I need it to be drawn in screen coordinates somehow, so that it doesn't move.

    I could use some advice on how to accomplish something like this.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    If you don't want it to move, don't move it.

    The map only moves because you make it move, typically by having the vertex shader apply a transformation to the vertex coordinates before storing them in gl_Position.

    Any "overlays" should have their own transformation, which will normally be constant. You typically shouldn't try to control the size of the scale bar using a scaling transformation; modify the geometry instead. Scaling will look ugly (e.g. borders and tick marks will be stretched).

  3. #3
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    39
    Hi GClements,
    from your comments how you say that I don't apply movement transformations makes sense.

    The piece I am confused mostly is how to start the vertex coordinate data. My screen is 480 pixels wide, 762 high, I am going to position this about 3 pixels from the bottom and 3 from the left of the screen, use 75% of the width which is 360 pixels. Maybe I thinking about this wrong. My first attempt will be a singular horizontal line.

    So the initial line I'd like to create will be via screen dimensions {3,759,0,363,759,0} or {-237,-378,0,597,-378,0} if the origin of this is in the center.

    Also would I creating a new model, projection, view, mvp matrices for this?
    Last edited by Hank Finley; 10-16-2013 at 01:08 AM.

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by Hank Finley View Post
    Also would I creating a new model, projection, view, mvp matrices for this?
    If you're using shaders, you don't necessarily need separate model-view and projection matrices, particularly for 2D (for 3D, you often need to separate them as lighting calculations need to be done before perspective projection).

    But the general point is that you wouldn't use the same matrices (or probably even the same shaders) for the scale bar as for the map.

    The map's transformation will typically include scaling and translation based upon zoom and pan, while the scale bar's transformation would have neither (any scaling would be performed by modifying the vertices).

  5. #5
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    39
    These almost sound contradictory: "If you're using shaders, you don't necessarily need separate model-view and projection matrices" and "But the general point is that you wouldn't use the same matrices (or probably even the same shaders)".

    Do you mean once I draw my map I somehow reset the model-view, projection matrices for my scalebar, so they are not seperate as such but not the same either?
    So hypothetically I have drawn my map, before I start my scalebar draw function, I change my view and projection matrix from settings for the map to the setting for the scalebar, these settings will be constant. Then I perform all the multiplication, apply shaders etc and draw away.

    My scalebar initial line vertex data I mentioned above? Am I going down the right track there? All the rest of my vertices on the map are 152.34545,-27.098945,,etc.
    Last edited by Hank Finley; 10-16-2013 at 01:32 AM.

  6. #6
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    39
    Started playing around with what I understood from your advice and created it without issue. I created a new view and projection in the existing matrices, these values were the size of the screen with the origin at the center.
    Just needed to make sure that they get set back to the map matrices when required.
    Thanks GClements!

  7. #7
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by Hank Finley View Post
    These almost sound contradictory: "If you're using shaders, you don't necessarily need separate model-view and projection matrices"
    I mean that you only need one matrix (model-view-projection), not two (model-view and projection). The fixed-function pipeline has separate model-view and projection matrices because lighting calculations are performed after the model-view transformation but before the projection transformation. If you aren't using the fixed-function pipeline (which doesn't exist in OpenGL ES 2) and either aren't performing lighting calculations or aren't using a perspective projection, then there isn't any need for separate model-view and projection transformations.

    Quote Originally Posted by Hank Finley View Post
    Do you mean once I draw my map I somehow reset the model-view, projection matrices for my scalebar, so they are not seperate as such but not the same either?

    So hypothetically I have drawn my map, before I start my scalebar draw function, I change my view and projection matrix from settings for the map to the setting for the scalebar, these settings will be constant. Then I perform all the multiplication, apply shaders etc and draw away.
    Yes. You set the transformation(s) for the map based upon zoom/pan, draw the map, set different transformation(s) for the scale bar, draw the scale bar. You might even use different shaders for the map and the scale bar (if one set of shaders works fine for both, all well and good, but having one set of shaders which works for different types of object can end up being more complicated than having different shaders for each type of object).

    My scalebar initial line vertex data I mentioned above? Am I going down the right track there? All the rest of my vertices on the map are 152.34545,-27.098945,,etc.
    The scale bar vertices would typically use "screen" coordinates (not necessarily pixel coordinates), not cartographic coordinates. If you want to make the scale bar longer or shorter, you'd move the vertices rather than changing the transformation (the reason being that changing the transformation would affect the size of tick marks, text, etc).

Tags for this Thread

Posting Permissions

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