[CSGL] Bitmaps laden
-
Hi,
Ich hab mir bei NeHe das Tutorial zum Texturen laden angeschaut und adaptiert. Nun schmiert mein Programm jedoch immer ab, wenn ich ein Bild laden möchte, das nicht genau 256x256 px gross ist. Da ich eine Kugel texturieren möchte, bräuchte ich eines, das 2:1 (width:height) gross ist. Liegts nun an OpenGL oder an .NET (namentlich an der BitmapData - Klasse und deren Verwendung hier)?
public static bool LoadTextures(uint[] texture) { // ... // hier lade ich zunaechst das bild image.RotateFlip(RotateFlipType.RotateNoneFlipY); System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); GL.glGenTextures(1,texture); // Create Nearest Filtered Texture GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0]); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); //Hier springt das Programm in Wald GL.glTexImage2D( GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB, rect.Width, //<-- Error falls Width != Height rect.Height, //<-- 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, bitmapdata.Scan0 // <- zeiger auf bitmap ); image.UnlockBits(bitmapdata); image.Dispose(); return true; }