last day (15 days later) » 

4:18 PM
0
A: Android OpenGL ES 2.0 VBO

DiversityIt seams that the stride of the vertexAttributePointer method is always 0. Which means you override the vertex positions within the vertex buffer with you color values. GLES20.glVertexAttribPointer(colourAttribute, this.colourValuesCount, GLES20.GL_FLOAT, false, **0**, 0); You have to increase...

 
I did everything you suggested and the only thing that worked was adding a fixed color, the problem is that the glGetAttribLocation is returning -1, which can't be right, so I don't think the shader is even getting the color from the program itself.
Wow, I just checked LogCat again, now there is another problem "<core_glUseProgram:1545>: GL_INVALID_OPERATION and aparently "GL_INVALID_OPERATION is generated if program is not a program object. GL_INVALID_OPERATION is generated if program could not be made part of current state." So maybe there might be a problem with the shader as well.
 
Did you already check if the vertexPositionAttribut is initialized correctly
Yes in my oppinion the problem must be the shaders. If they would compile correctly than the attributes could be bound correctly.
 
Ok, how can make sure it is working properly?
 
I see another problem right now. You missed to link the shader and enable it using glLinkProgram and glUseProgram. Have a look here: stackoverflow.com/questions/4850025/…
 
Ok, I have now got an error, it is: Could not link the program. Invalid fragment shader. Link cannot proceed.
 
4:19 PM
remove the uniform qualifier from the colour vec could be one possibility
#version 150

out vec4 colorOut;

void main()
{
colorOut = vec4(1.0, 0.0, 0.0, 1.0);
}
This is the simplest fragment shader possible taken from here: lighthouse3d.com/tutorials/glsl-core-tutorial/fragment-shader
in this case you have to replace colorOut with your colour attribute name
 
Ok fixed that problem, forgot a semicolon at the end of color, when i edited it earlier. It still doesn't show up though, i just dont get it, the colourAttribute is still -1, as if it cant actually access that attribute in the first place.
How would i use colorOut to set the fragColor?
Actually, just tested it, it comes out with 'out' being a syntax error, this might mean that OpenGL ES 2.0 doesn't support 'out'
 
ok than just use attrib
attribute instead of out
have a look here. Out should be supported de.wikipedia.org/wiki/OpenGL_ES_Shading_Language
The supported shader version is important.
 
4:49 PM
Ok so i have tried out, and currently the shader looks like this:
/* The Android shader code */
private static final String[] androidVertexShaderCode = new String[] {
"attribute vec4 colour;" +
"attribute vec4 vertexPosition;" +
"void main() {" +
" gl_Position = vertexPosition;" +
"}" };

private static final String[] androidFragmentShaderCode = new String[] {
"varying vec4 colour;" +
"void main() {" +
" gl_FragColor = colour;" +
"}" };
To setup the shader i am using:
GLES20.glAttachShader(this.androidShader.program, loadShader(GLES20.GL_VERTEX_SHADER, androidVertexShaderCode[0]));
GLES20.glAttachShader(this.androidShader.program, loadShader(GLES20.GL_FRAGMENT_SHADER, androidFragmentShaderCode[0]));
GLES20.glLinkProgram(this.androidShader.program);
If i set the color within the shader it works fine, but externally, the location is still -1, causing an invalid_value error from glEnableVertexAttribArray
 
When you set a fixed color the triangle is shown?
 
5:05 PM
yes
 
5:18 PM
use the "attribut" qualifier for the colour also within the fragment shader.
 
Didn't work, it says that attribute variables are only supported in vertex shaders, when i say it works, it works from the vertex shader, i can set it there and it works fine, it is passed the variable over to the fragment shader from the vertex shader.
 
Ok it works like this. You can just pass the color the the vertex shader.
The gpu than calculates the colors for each pixels by interpolating the colors of each vertex.
so you have to define a variny attribute fr_colour within the vertex shader
and assign the value of colour to it
attribute vec colour;
varying vec4 fColour;
main () {
fColour = colour;
this was the vertex shader
the fragment shader should declare
varying vec4 fColourM
vois main() {
gl_FreagColor = fColour;
The varying vec4 fColour enables you to pass the color between vertex and fragment shader.
 
5:42 PM
Wow, for a moment I wasn't sure whether it would work, because i didn't realise you have to use an attribute for glEnableVertexAttribArray. Thank you so much! It works, and it has even solved a problem I though I would end up having when trying to have each vertex a different colour. :)
 
Good luck and have fun. Programming OpenGL is really amazing and interesting topic but quite complicated stuff.
 
Thank you :)
 
Yes it all makes sense when you know that you define the structur of the vertex buffer by specifying the vertex attributes. In your case 4 times float for the position and 4 times float for the color. Within the vertexBuffer data than each vertex is associated with the color and later normals and so on. The shader act now upon this vertex attribute structure.
 

last day (15 days later) »