roriron's picture

Problem with texture

I 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()
        private int textID;
        private void glControl1_Load(object sender, EventArgs e)
            textID = TexLib.TexUtil.CreateTextureFromBitmap(Resource1.round2);
            int Width = glControl1.Width;
            int Height = glControl1.Height;
            GL.Viewport(new System.Drawing.Size(Width, Height));
            GL.Ortho(0, Width, 0, Height, -1, 1);
        private void glControl1_Paint(object sender, PaintEventArgs e)
            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);

I don't know what's wrong, pleased help me!!!

Inline Images


Comment viewing options

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

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.

the Fiddler's picture

Also try adding GL.Enable(EnableCap.Texture2d) in your glControl1_Paint method.

roriron's picture

Thanks for your help!
I changed the texture size and it worked, the size must be the power of two.

roriron's picture

I had another problem.
I made a 3D cube and used texture and it worked well. But when I tried antialiasing function by using:
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.

cube.JPG20.59 KB
the Fiddler's picture

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.

c2woody's picture

Try replacing the default texture wrapping (repetition) with clamping, and change the border color to something different from black:

  GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
  GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
  GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, 0x55555555);