Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL and layouts

I'm using OpenGL to render a game view in my android application. The game is turn based and I wish to add some buttons to the interface. I'd prefer to use standard Android widgets, structured in an XML-generated layout (or, if I have to, a hardcoded layout) and put the OpenGL view in its own window as part of that layout.

So in regards to this, I have 3 questions:

1: Is such a thing possible? I've done a few half-hearted tries, but have had no luck so far.

2: Is such a thing advisable? Does it carry a significant performance penalty, for example, over using OpenGL-based homebrew widgetry?

3: Is it possible to pass particular arguments to instances created in XML layouts? For example, my current OpenGL view has three arguments in its constructor; is it somehow possible for me to invoke that particular constructor with particular parameters when it's part of a layout?

like image 923
Hnefi Avatar asked May 24 '10 18:05

Hnefi


People also ask

What is GLSL layout?

A number of OpenGL Shading Language variables and definitions can have layout qualifiers associated with them. Layout qualifiers affect where the storage for a variable comes from, as well as other user-facing properties of a particular definition.

How do you use uniforms in OpenGL?

Uniforms are intended to be set by the user from OpenGL, rather than within the shader. However, you can initialize them to a default value using standard GLSL initalizer syntax: uniform vec3 initialUniform = vec3(1.0, 0.0, 0.0); This will cause the uniform to have this vector as its value, until the user changes it.

Is gl_FragColor deprecated?

Yes, gl_FragColor is deprecated. You should use the following syntax: layout(location = 0) out vec4 diffuseColor; It is included in the GLSL 4.60 spec under the section 7.1.

What is Std140?

Std140 is a standardized memory layout for GLSL shader interface blocks (e.g. uniform blocks). An interface block is a group op typed GLSL variables. For details on the layout rules for std140, please refer to the section 2.12. 6.4 “Standard Uniform Block Layout” of the OpenGL ES 3.0 Specification.


1 Answers

Not only are these things possible, they are commonplace! The OpenGL SurfaceView is just another View in Android and you can layer anything you want over top of it. In the app that I am building we use OpenGL to render interesting backgrounds while layer the entire menu overtop of it. There are no more significant performance concerns that you would have with OpenGL by itself. You can use xml layouts or generate all of your ui elements programmatically or do some combination of the two. Even if you want to use xml to instantiate your ui you can get access to the elements and manipulate them based on state.

like image 83
CaseyB Avatar answered Sep 22 '22 05:09

CaseyB