Jump to content
  • Advertisement
Sign in to follow this  
Steve5050

OpenGL Water Waves

This topic is 3742 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, Using Vb.Net 2003 with DX 9.0c I've been trying to make water waves for many days now and I just cannot figure it out. This is code from NeHe Lesson 11 in opengl I'll see if I can upload the code with the exe so you can see I want to do something similar to the lesson. I already tried to change the code over to dx but it's not working. Actually the source and exe is Here.
Private Shared points(44, 44, 2) As Single
Private Shared Function DrawGLScene() As Boolean
			Dim x, y As Integer
			Dim float_x, float_y, float_xb, float_yb As Single

			Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT) ' Clear The Screen And The Depth Buffer
			Gl.glLoadIdentity() ' Reset The View
			Gl.glTranslatef(0, 0, -12)
			Gl.glRotatef(xrot, 1, 0, 0)
			Gl.glRotatef(yrot, 0, 1, 0)
			Gl.glRotatef(zrot, 0, 0, 1)
			Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture(0))
			Gl.glBegin(Gl.GL_QUADS)
				For x = 0 To 43
					For y = 0 To 43
						float_x = x / 44.0f
						float_y = y / 44.0f
						float_xb = (x + 1) / 44.0f
						float_yb = (y + 1) / 44.0f
						Gl.glTexCoord2f(float_x, float_y)
						Gl.glVertex3f(points(x, y, 0), points(x, y, 1), points(x, y, 2))
						Gl.glTexCoord2f(float_x, float_yb)
						Gl.glVertex3f(points(x, y + 1, 0), points(x, y + 1, 1), points(x, y + 1, 2))
						Gl.glTexCoord2f(float_xb, float_yb)
						Gl.glVertex3f(points(x + 1, y + 1, 0), points(x + 1, y + 1, 1), points(x + 1, y + 1, 2))
						Gl.glTexCoord2f(float_xb, float_y)
						Gl.glVertex3f(points(x + 1, y, 0), points(x + 1, y, 1), points(x + 1, y, 2))
					Next y
				Next x
			Gl.glEnd()

			If wiggle_count = 2 Then
				For y = 0 To 44
					hold = points(0, y, 2)
					For x = 0 To 43
						points(x, y, 2) = points(x + 1, y, 2)
					Next x
					points(44, y, 2) = hold
				Next y
				wiggle_count = 0
			End If

			wiggle_count += 1

			xrot += 0.3f
			yrot += 0.2f
			zrot += 0.4f
			Return True ' Keep Going
	 End Function

Not only have I tried that code, I tried making a grid and moving the vertices and nothing is working for me, I'm screwing up and can't figure it out. If you run that lesson it will give you some insight on what I'm trying to do. Thanks Steve

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I already tried to change the code over to dx but it's
not working.

Are you working in DirectX or OpenGL, Steve5050? You mention DX 9.0c but your question appears to be related to OpenGL. If so, you should consider posting to the OpenGL forum.

If you're trying to rewrite the OpenGL code for DirectX:
1. You need to describe what's "not working."
2. Post some DirectX code for people to look at.

Share this post


Link to post
Share on other sites
Using Directx.
That is why I said I was using dx and posted in the dx forum.
I was trying to convert the ogl code to use in dx.
What isn't working is that it doesn't show up.
Just a small flicker of a triangle was flickering if I aimed
the at I just the right way,I also didn't have culling set to none
while trying the code
No errors.
Have you seen the source and exe in the link?
I cut out the code that I was trying to use but it basically wasn't
much differnt than the ogl code.

Gl.glVertex3f(points(x, y, 0), points(x, y, 1), points(x, y, 2))

Hold on I just spotted my code, this would be one of the ways
I tried it:

Private Shared points(44, 44, 2) As Single

Public Function LoadVB() As Boolean
vb = New VertexBuffer(GetType(CustomVertex.PositionNormalTextured), numVerts, Device, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Managed)
verti = New CustomVertex.PositionNormalTextured(numVerts) {}
vb.Lock(0, 0)
Dim x, y As Integer
Dim float_x, float_y, float_xb, float_yb As Single
For x = 0 To 43
For y = 0 To 43
float_x = x / 44.0F
float_y = y / 44.0F
float_xb = (x + 1) / 44.0F
float_yb = (y + 1) / 44.0F

verti(0).X = points(x, y, 0)
verti(0).Y = points(x, y, 1)
verti(0).Z = points(x, y, 2)
verti(0).Tu = float_x
verti(0).Tv = float_y

verti(1).X = points(x, y + 1, 0)
verti(1).Y = points(x, y + 1, 1)
verti(1).Z = points(x, y + 1, 2)
verti(1).Tu = float_x
verti(1).Tv = float_yb

verti(2).X = points(x + 1, y + 1, 0)
verti(2).Y = points(x + 1, y + 1, 1)
verti(2).Z = points(x + 1, y + 1, 2)
verti(2).Tu = float_xb
verti(2).Tv = float_yb

verti(3).X = points(x + 1, y, 0)
verti(3).Y = points(x + 1, y, 1)
verti(3).Z = points(x + 1, y, 2)
verti(3).Tu = float_xb
verti(3).Tv = float_y

Next y
Next x
'vb.SetData(verti, 0, LockFlags.None)
vb.Unlock()
Return True
End Function





Ok let me know what you think.

Thanks
Steve

Share this post


Link to post
Share on other sites
Quote:
Have you seen the source and exe in the link?

The link you provided was to the NeHe OpenGL tutorial. That was the reason for my question.

EDIT:
Have you tried to render just a single triangle, to ensure your rendering loop is correct?

EDIT2:
Quote:
I also didn't have culling set to none

Try setting cullmode to CULLNONE.

OpenGL uses a right-hand coordinate system and DirectX uses left-hand. If you use the same routine for setting up the points that the tutorial uses, all your triangles will be CCW instead of CW.

If so, you should be able to make the change in your routine to:

verti(...).X = points(x, y, 2)
verti(...).Y = points(x, y, 1)
verti(...).Z = points(x, y, 0)


[Edited by - Buckeye on July 16, 2008 4:02:17 PM]

Share this post


Link to post
Share on other sites
Ah, I put the link in because the source and exe is
at the bottom of the tutorial, I can see why that would be
confusing, usually you get sent to a file download.
Sorry about that,I get the confusing part now.

Share this post


Link to post
Share on other sites
See my edited comments above. I was editing during your last post.

EDIT: I think I misread your code. IGNORE the comment about changing the points!

You should be able to generate CCW quads by changing the order of the vertex loading:

verti(3).X = points(x, y, 0)
verti(3).Y = points(x, y, 1)
verti(3).Z = points(x, y, 2)
...
verti(2).X = points(x, y, 0)
verti(2).Y = points(x, y, 1)
verti(2).Z = points(x, y, 2)
...
verti(1).X = points(x, y, 0)
verti(1).Y = points(x, y, 1)
verti(1).Z = points(x, y, 2)
...
verti(0).X = points(x, y, 0)
verti(0).Y = points(x, y, 1)
verti(0).Z = points(x, y, 2)

Share this post


Link to post
Share on other sites
I going to go back and try it again,judging by your answer
your not seeing any thing wrong with the code.
I'll be back.

Share this post


Link to post
Share on other sites
I tried reversing the order and that showed nothing at all.
I tried drawuserprimitives and didn't get anywhere, I'll put
up all the code,this is the closest I came to seeing anything.
I did test a box in the code and it worked perfectly.
I'm thinking getting 4 out 3 might be the problem,I'm not coming
up with the solution, thats for sure. I tried going with three
verts and lost that battle.


Private Shared points(44, 44, 2) As Single
Private numVerts As Integer = 44
Private Verts() As CustomVertex.PositionTextured

Public Sub LoadVB()
vb = New VertexBuffer(GetType(CustomVertex.PositionTextured), numVerts, Device, Usage.WriteOnly, VertexFormats.Position And VertexFormats.Texture0, Pool.Managed)
Dim Verts(numVerts) As CustomVertex.PositionTextured
Dim x, y As Integer
Dim float_x, float_y, float_xb, float_yb As Single
For x = 0 To 43
For y = 0 To 43
float_x = x / 44.0F
float_y = y / 44.0F
float_xb = (x + 1) / 44.0F
float_yb = (y + 1) / 44.0F

Verts(0) = New CustomVertex.PositionTextured(points(x, y, 0), points(x, y, 1), points(x, y, 2), float_x, float_y) '0
Verts(1) = New CustomVertex.PositionTextured(points(x, y + 1, 0), points(x, y + 1, 1), points(x, y + 1, 2), float_x, float_yb) '1
Verts(2) = New CustomVertex.PositionTextured(points(x + 1, y + 1, 0), points(x + 1, y + 1, 1), points(x + 1, y + 1, 2), float_xb, float_yb) '2
Verts(3) = New CustomVertex.PositionTextured(points(x + 1, y, 0), points(x + 1, y, 1), points(x + 1, y, 2), float_xb, float_y) '3
Next y
Next x
vb.SetData(Verts, 0, LockFlags.None)

End Sub

Public Sub Render()
Device.RenderState.Lighting = False
Device.RenderState.ZBufferEnable = True
Device.Transform.World = Me.Mat1
Device.VertexFormat = CustomVertex.PositionTextured.Format
Device.SetTexture(0, Tex)
Device.SetStreamSource(0, vb, 0)
Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, numVerts / 3)
End Sub






Share this post


Link to post
Share on other sites
Wow. You've got several problems, now that I see the code.

The biggest problem:
1. You don't increment the Verti() subscript. You continually load data into just Verti(0) .. (1) .. (2) ..(3).

2. The OpenGL data is arranged to render quads ( Gl.glBegin(Gl.GL_QUADS) ) and you're rendering the same data as a triangle strip. I'm pretty sure that won't work. Your best bet may be to create 2 triangles ( 6 vertices ) for each set of quad data and render a triangle list.

3. As I mentioned in one of my previous posts, OpenGL uses CW axes and DirectX use CCW axes so the data has to be rearranged.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!