Jump to content

  • Log In with Google      Sign In   
  • Create Account

Vertexshader not working


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 28 October 2012 - 01:12 PM

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

Sponsor:

#2 PAndersson   Members   -  Reputation: 394

Like
0Likes
Like

Posted 28 October 2012 - 01:57 PM

Do you somehow set your homogenus coordinate beforehand? To me, it seems like you do not.

#3 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 28 October 2012 - 02:00 PM

No, but it makes no difference if i set the w-component to 1 or 0 or any other value.

#4 PAndersson   Members   -  Reputation: 394

Like
0Likes
Like

Posted 28 October 2012 - 02:22 PM

What does your glVertexAttribPointer calls look like? Anyway, you should still set your w-component to 1.

#5 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 28 October 2012 - 02:28 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS