Hi everyone,
I found it a bit hard to set an appropriate title, but ill describe my problem a bit more in detail now.
Im currently trying to render a triangle using screen coordinates on my android device. I started as usual with a ortho matrix that projects the coordinates into device coordinates. As it didnt work i thought ill just skip the matrix for a moment and check from hardcoded values how i need to modify my code. So i started with the following set of coordinates:
[source lang="java"] float[] squareCoords = {
20.0f * 2 / 1280.0f, 30.0f * 2 / 750.0f, 0,
20.0f * 2 / 1280.0f, 0, 0,
0, 0, 0,
};[/source]
And a simple shader with:
[source lang="cpp"]attribute vec4 vPosition;
void main() {
gl_Position = vPosition;
}[/source]
So far so good, i get a little triangle around the middle of the screen vertically mirrored, everything as expected. In a next step i changed my coordinates:
[source lang="java"] float[] squareCoords = {
20.0f, 30.0f, 0,
20.0f, 0, 0,
0, 0, 0,
};[/source]
But also modified my shader:
[source lang="cpp"]attribute vec4 vPosition;
void main() {
gl_Position = vec4(
vPosition.x * 2 / 1280.0f,
vPosition.y * 2 / 750.0f,
vPosition.z,
vPosition.w);
}[/source]
In my opinion this is exactly the same thing as before, i just moved the projection to the shader instead of hardcoded values, but now the screen is completely black, nothing gets rendered at all!
Am i missing something?
Greetings
Plerion
Vertexshader not working
Do you somehow set your homogenus coordinate beforehand? To me, it seems like you do not.
What does your glVertexAttribPointer calls look like? Anyway, you should still set your w-component to 1.
glVertexAttribPtr(index /* obtained from glGetAttribLocation with vPosition and is 0 */, 3, GL_FLOAT, false, 0, elem.getStream())
getStream is a FloatBuffer where i write the coordinates from above.
Just to mention: With the first version i posted the triangle is OK, in the second version there is no triangle.
getStream is a FloatBuffer where i write the coordinates from above.
Just to mention: With the first version i posted the triangle is OK, in the second version there is no triangle.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement