
Problem with texture
Posted Thursday, 11 March, 2010 - 10:43 by roriron inI tried to use TexUtil I've found here , just a simple program with glControl, but it didn't work, it only display a white rectangle.
Here my code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenTK; using OpenTK.Graphics.OpenGL; namespace TestProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private int textID; private void glControl1_Load(object sender, EventArgs e) { TexLib.TexUtil.InitTexturing(); textID = TexLib.TexUtil.CreateTextureFromBitmap(Resource1.round2); int Width = glControl1.Width; int Height = glControl1.Height; GL.Viewport(new System.Drawing.Size(Width, Height)); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, Width, 0, Height, -1, 1); } private void glControl1_Paint(object sender, PaintEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.BindTexture(TextureTarget.Texture2D,textID); GL.Begin(BeginMode.Quads); GL.TexCoord2(0,1); GL.Vertex2(10,10); GL.TexCoord2(1, 1); GL.Vertex2(100, 10); GL.TexCoord2(1, 0); GL.Vertex2(100, 100); GL.TexCoord2(0,0); GL.Vertex2(10, 100); GL.End(); glControl1.SwapBuffers(); } } }
I don't know what's wrong, pleased help me!!!
Thanks!!!


Comments
Re: Problem with texture
Check your texture size. Texture size should be power of two. Modern video cards support non power of two textures. So if you have old video card you have this problem.
Re: Problem with texture
Also try adding
GL.Enable(EnableCap.Texture2d)in your glControl1_Paint method.Re: Problem with texture
Thanks for your help!
I changed the texture size and it worked, the size must be the power of two.
Thanks!!!
Re: Problem with texture
I had another problem.

I made a 3D cube and used texture and it worked well. But when I tried antialiasing function by using:
GL.Enable(EnableCap.PolygonSmooth);All faces of the cube appear a black line (like the picture below).
Anyone can show me how to make the cube smoothly without any black line.
Thanks!!!
Re: Problem with texture
I don't know how to make PolygonSmooth behave in this case, but it's generally simpler to enable fullscreen antialiasing by passing the correct GraphicsMode to your GameWindow or GLControl constructor:
new GraphicsMode(32, 24, 0, 4)should do the trick for 4x antialiasing.Re: Problem with texture
Try replacing the default texture wrapping (repetition) with clamping, and change the border color to something different from black: