Load a bmp on to a GLview using CsGL

V

Vin

Hi,

I save the drwan stuff on a GLView using CsGL like this:
Size s = Size;
s.Width = 540;
s.Height = 435;
Bitmap b = new Bitmap(s.Width, s.Height,
PixelFormat.Format32bppArgb);
BitmapData bd = b.LockBits(new Rectangle(0, 0, s.Width,
s.Height),ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
CsGL.OpenGL.GL.glReadPixels(0, 0, s.Width, s.Height,
CsGL.OpenGL.GL.GL_BGRA_EXT, CsGL.OpenGL.GL.GL_UNSIGNED_BYTE,
bd.Scan0);
b.UnlockBits(bd);
b.RotateFlip(RotateFlipType.Rotate180FlipX);
b.Save(@"c:\test.bmp", ImageFormat.Bmp);

Now I want to load the same test.bmp on click of a load button.
Can someone share a code snippet for the same. I guess we could use
glDrawPixels. But i m not sure how.

Help is much appreciated.

Cheers
Vin
 
N

Nicholas Paldino [.NET/C# MVP]

Vin,

Are you saying that you want to draw what you are drawing in the bitmap
to the button when it is clicked? If you want to do this, then you will
have to create the bitmap as you are doing now. Then, you would get the
Graphics object for the button (on the click), and draw the bitmap on the
graphics context for the button (through a call to the DrawImage method on
the Graphics instance).

Hope this helps.
 
J

Joel Martinez

well, I've never used CsGL, but I assume the API is similar to good
ol' regular ogl.

Once you load the bitmap into memory (probably using a
System.Drawing.Bitmap), you probably want to map the texture onto a
quad or something

glBindTexture(GL_TEXTURE_2D, mybmp);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

Hope that helps,
Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog
 
V

Vin

No Nick, I got a saved bmp on my hard disk. which i just want to load
on to the GLView. GLView is the graphics panel on which I want to load
the bmp file. GLView is from where I saved the drawn image
earlier.

Could you provide some code snippet to do this, just like the one I ve
posted for save?

Thanks
Vin
 
Top