Jump to content

View more

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Vertexshader not working

4: Adsense

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   

381
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

#2 PAndersson   Members   

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   

381
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   

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   

381
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.