Advertisement

[C#/OpenGL] Question about glTexImage2D

Started by May 17, 2004 04:10 PM
3 comments, last by Del Snd of Thndr 20 years, 6 months ago
Hey guys! I've done a quick search over the forums, and I can't quite find the solution to my problem. Basically, I'm just trying to create a sphere and paste a bitmap of the earth onto that sphere. I'm using C# and the NeHe base code, and using NeHe Lesson 06 as a guideline. I have downloaded the C# edition of the lesson 6 code and compiled to the same error. Could someone please help me?? Here's my code:

#region Earth Map Setup

//Enable GL_TEXTURE_2D to map the bitmap to the earth.

GL.glEnable(GL.GL_TEXTURE_2D);

//Create a new bitmap

Bitmap bmp = new Bitmap("earth.bmp");

//Do not flip or rotate the image.

bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);

//Create a rectangle that contains the whole of the bitmap.

Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

//Create a BitmapData object, and lock the bits of the image.

System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

GL.glGenTextures(1, texture);
GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0]);
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, 
     bmp.Width, bmp.Height, 0, GL.GL_BGR_EXT, 
     GL.GL_UNSIGNED_BYTE, bmpData.Scan0);
GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,  
     (int)GL.GL_LINEAR);  // Linear Filtering

GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR);  // Linear Filtering


//Unlock the bits.

bmp.UnlockBits(bmpData);
//Get rid of the image.

bmp.Dispose();

#endregion
 
And here are the errors: The best overloaded method match for 'OpenGL.GL.glTexImage2D(uint, int, int, int, int, int, uint, uint, object[])' has some invalid arguments Argument '9': cannot convert from 'System.IntPtr' to 'object[]' If someone could help me, I sure would appreciate it. Thanks! Edit: Fixed source ~del [edited by - Del Snd of Thndr on May 17, 2004 5:12:00 PM]
~del
Im not at all great at C# but the glTexImage2D requires an array of objects for the image data (9th parameter).

Your code is sending it a pointer to the first data value.

Like I say tho...I dunno how you''d get the data array from that bmp thingy tho. *Shrugs*

Best have a look at those BMP objects again matey

Hope that helped a little.

Advertisement
Hey, are you using the Nehe C# basecode? If so, then I must admit that I put that together and it''s not entirely tested(Embarassed shrug). What I suggest is in the csOGL.cs file, or whatever similar name it has, search for glTexImage2D. The function is probably prototyped wrong. Replace the object[] with IntPtr. It will compile, but I don''t know if it will work! Let me know, and also any other bugs you come across and I''ll submit an update!
Thanks for both replies! I''ll check that out when I get to work tomorrow. I''ll let you know how things work out, variant. Thanks again!

~del
~del
I would recommend switching to using the Tao Framework, which appears to have the most full featured .NET wrapper of OpenGL that I have seen. It also wraps several other usefull dll''s, such as DevIL, CG, and OpenAL. The developer is also a supporter of the Axiom engine.

J.W.

This topic is closed to new replies.

Advertisement