Stupid_2D's picture

Problem with textured VBO

Hello Everyone,

I am currently working on VBOs and everything works fine, despite texturing. Well my problem is, that when i draw a simple 2D Quad, it has not the texture stretched over its size but more like tiled.

So if the square is 5x units, i have 25 times the same texture on it.

Anyone know why?

                        GL.Enable(EnableCap.Texture2D);
			LoadTexture("cross.png");  
 
			VBO = new VertexBufferObject();
			VBO.VertexData = new Vector3[] { 
				new Vector3 (-1.0f, -1.0f, 0.0f), 
				new Vector3 (1.0f, -1.0f, 0.0f), 
				new Vector3 (1.0f, 1.0f, 0.0f), 
				new Vector3 (-1.0f, 1.0f, 0.0f)
			};
			VBO.TextureData=new Vector3[] { 
				new Vector3 (-1.0f, -1.0f, 0.0f), 
				new Vector3 (1.0f, -1.0f, 0.0f), 
				new Vector3 (1.0f, 1.0f, 0.0f), 
				new Vector3 (-1.0f, 1.0f, 0.0f)
			};
 
			VBO.IndicesData = new uint[] { 
				0, 1, 2, 3
			};
public void GenerateBuffers()
...
			if (TextureData != null)
			{
				GL.GenBuffers(1, out TextureBufferID);
				GL.BindBuffer(BufferTarget.TextureBuffer, TextureBufferID);
				GL.BufferData<Vector3>(BufferTarget.TextureBuffer, 
				                       new IntPtr(TextureData.Length * Vector3.SizeInBytes),
				                       TextureData, BufferUsageHint.StaticDraw);
			}
...
public void DrawBuffers()
...
			if(TextureBufferID!=0)
			{
				GL.BindBuffer(BufferTarget.TextureBuffer, TextureBufferID);
				GL.TexCoordPointer(3,TexCoordPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);
				GL.EnableClientState(ArrayCap.TextureCoordArray);
			}
...

Check Attached picture:

It should be one cross, not so many...

Inline Images

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
AmzBee's picture

This looks like its more to do with your texture loading routine, if it was the VBO set-up, then I'd imagine you'd have different problems. Try something like the following in your texture loading routine, and see if it makes a difference:

GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);

Aimee.

Stupid_2D's picture

Thank you for your reply, though I am sorry that youcouldnt help me here since I just found a working soloution here. Changed a few things and now i got a working VBO Manager :)
http://www.opentk.com/node/2318