• Advertisement
Sign in to follow this  

Vertexshader not working

This topic is 1912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
No, but it makes no difference if i set the w-component to 1 or 0 or any other value.

Share this post


Link to post
Share on other sites
What does your glVertexAttribPointer calls look like? Anyway, you should still set your w-component to 1.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement