Archived

This topic is now archived and is closed to further replies.

[C#/OpenGL] Question about glTexImage2D

This topic is 4961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites