Moving+scaling individual OpenGL UI controls
I'm new to OpenGL and I've just read a nice tutorial about OpenGL 2.0. My target is OpenGL ES 2.0.
I need to create a UI which consists of controls. Controls can be moved in edit mode. I think that creating vertices for each control and uploading them to the GPU, then mapping this all to the screen with a simple vertex shader has its limitations when it comes to moving and scaling individual parts (controls). Am I right here?
I think it woul开发者_如何学运维d be better to create uniform attributes for each control, like width/height/left/top/other control-definied attribs like slider position, etc... Then map the constrant vertices intelligently to the screen with a clever shader. The host app then just had to update the uniform attribs for a control instead of uploading new sets of vertices each time.
What do you recommend? Is there an example or tutorial focusing on this?
Well your problem is that that shader can only work with one vertex at time and can't access others unless they are uniforms. This is nice example for geometry shader, you could just send center and it would produce everything you like... circle, box.. with few other uniforms like aspect or size...
But you can do with vertex shader fine aswell. You will create your vertices realtive to center. For 2x2 square vertices would be like:
1. -1, -1
2. 1, -1
3. 1, 1
4. -1, 1
You can then just move center of this shape and set it scaling. As you see you will just scale 2D vectors, easy task, and add them to center position.. this way you get 4 positions at right place and you can draw your square. Idea of this is that you can create any shape (not just boxes which are possible with width, height, top, left..) and you can upload these shapes to texture buffer. For drawing with shader you just specify which shape, where is center and what is the size.. it will be quite fast and easy to add new things I think..
And yes you are right mapping everything and updating is very slow thing. I was actually doing some research with mapping yesterday and it proved quite bad performance..
精彩评论