miujin's picture

textures doesn't work

Hi,

since hours I search the error in my code, but I doesn't find some.

I only want to map a texture on a quad, but when I render it, the quad has the color of my last glColor call and there is nothing to see of my texture.

        public int AddRenderObject(List<Bitmap> bmps, List<float[]> positions)
        {
            KTC_DicomObject dicom = new KTC_DicomObject();
            dicom.textureIDs = new List<int>();
            Bitmap bmp = bmps[0];
 
            System.Drawing.Imaging.BitmapData texturedata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                                                        System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                                        System.Drawing.Imaging.PixelFormat.Format24bppRgb);
 
            int texID = GL.GenTexture();
            dicom.textureIDs.Add(texID);
            GL.BindTexture(TextureTarget.Texture2D, dicom.textureIDs[0]);
 
            //GL.textur
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, texturedata.Width, texturedata.Height, 0,
                          PixelFormat.Rgb, PixelType.UnsignedByte, texturedata.Scan0);
 
            float[] coordinates = positions[0];
 
            dicom.ListID = GL.GenLists(1);
            //GL.Enable(EnableCap.Texture2D);
            //GL.BindTexture(TextureTarget.Texture2D, dicom.textureIDs[0]);
            GL.NewList(dicom.ListID, ListMode.Compile);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(0.0, 0.0);
            GL.Vertex3(coordinates[0], coordinates[1], coordinates[2]);
            GL.TexCoord2(1.0, 0.0);
            GL.Vertex3(coordinates[3], coordinates[4], coordinates[5]);
            GL.TexCoord2(1.0, 1.0);
            GL.Vertex3(coordinates[6], coordinates[7], coordinates[8]);
            GL.TexCoord2(0.0, 1.0);
            GL.Vertex3(coordinates[9], coordinates[10], coordinates[11]);
            GL.End();
            GL.EndList();
            //GL.BindTexture(TextureTarget.Texture2D, 0);
            //GL.Disable(EnableCap.Texture2D);
            bmp.UnlockBits(texturedata);
 
            m_dicomobj.Add(dicom);
 
            return m_dicomobj.Count - 1;
        }

An the code of my render function

                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, m_dicomobj[0].textureIDs[0]);
                GL.CallList(m_dicomobj[0].ListID);
                GL.Disable(EnableCap.Texture2D);