Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


opentk:how to read texture1D files


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 nickme   Members   -  Reputation: 205

Like
0Likes
Like

Posted 12 December 2012 - 07:35 PM

hi

i am trying to read a file into texture1D. i know how to read an image into texture2D. i had problem converting it to read texture1D. i just dont know how to use Bitmap..LockBits() for texture1D.

here is the code for loading texture2D:

[source lang="csharp"] static public int LoadTexture(string filename) { // If a filename isn't provided, throw an error. if (String.IsNullOrEmpty(filename)) throw new ArgumentException(filename); // Generate an OpenGL texture handle and bind to it. int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); // Load up the bitmap image from a file on the computer. Bitmap bmp = new Bitmap(filename); // Lock the image's data into system memory so it can be used by OpenGL. We are forcing a // 32-bit alpha/red/green/blue pixel format. BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // With the image locked, we can tell OpenGL to store the bitmap's scan data into our texture buffer. GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmpData.Width, bmpData.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0); // Last, we unlock the bitmap. At this point, the Bitmap is no longer needed and can be discarded. bmp.UnlockBits(bmpData); // We also need to tell OpenGL how to render the texture when it is either smaller or larger than the // original bitmap size. Here, we are using nearest as we want to see the pixels without any filtering. GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest); // Finally, we return the texture buffer handle back to the application for later use. return id; }[/source]

thanks

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS