public static int loadFromFile(string url, int filter_far, int filter_near) { try { Texture tex = new Texture(); tex.bitmap = Texture.loadBMP(url); if (tex.bitmap == null) { return -1; } GL.GenTextures(1, out tex.ID); tex.Bind(); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, filter_far); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, filter_near); GL.GetTexParameter(TextureTarget.Texture2D, GetTextureParameter.TextureMagFilter, out tex.filterFar); GL.GetTexParameter(TextureTarget.Texture2D, GetTextureParameter.TextureMinFilter, out tex.filterNear); Rectangle rect = new Rectangle(0, 0, tex.bitmap.Width, tex.bitmap.Height); System.Drawing.Imaging.BitmapData bitmapdata = tex.bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, tex.bitmap.Width, tex.bitmap.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, bitmapdata.Scan0); tex.bitmap.Dispose(); return tex.ID; } catch(ArgumentException) { Debug.Trace("Class Texture: Error creating Bitmap: " + url); return -1; } }
public void Render(ref Frustum frustum) { Frustum.InFrustumCheck nodeInFrustum = frustum.CubeInFrustum(mainNode.BoundingBox3D); if (((nodeInFrustum != Frustum.InFrustumCheck.OUT) && (mainNode.HasChilds()))) { bool checkFrustum = true; // if all boundingbox corner where inside the frustum, there is no need to check the childs too if (nodeInFrustum == Frustum.InFrustumCheck.IN) { checkFrustum = false; } Core.pushState(); //GL.Scale(terrainRef.scale); //GL.Translate(terrainRef.position); GL.Disable(EnableCap.Lighting); GL.Color4(1.0, 1.0, 1.0, 0); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); if (terrainRef.TextureID != -1) { Texture.Bind(terrainRef.TextureID); GL.Enable(EnableCap.Texture2D); } CheckNodeInsideFrustum(ref frustum, ref mainNode, checkFrustum); if (terrainRef.TextureID != -1) { GL.Disable(EnableCap.Texture2D); } GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.VertexArray); Core.popState(); } return; }