public Texture(Context context, string fileName) { if (string.IsNullOrEmpty(fileName)) { return; } GLES20.GlGenTextures(1, textureHandle, 0); //init 1 texture storage handle if (textureHandle[0] != 0) { //Android.Graphics cose class Matrix exists at both Android.Graphics and Android.OpenGL and this is only sample of using Android.Graphics.BitmapFactory.Options options = new Android.Graphics.BitmapFactory.Options(); options.InScaled = false; // No pre-scaling int id = context.Resources.GetIdentifier(fileName, "drawable", context.PackageName); Android.Graphics.Bitmap bitmap = Android.Graphics.BitmapFactory.DecodeResource(context.Resources, id, options); GLES20.GlBindTexture(GLES20.GlTexture2d, textureHandle[0]); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlNearest); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlNearest); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0); bitmap.Recycle(); handle = textureHandle[0]; } }
private static TexInfo CreateTexInfoFromBitmap(Bitmap bitmap) { TexInfo ret = null; if (bitmap != null) { ret = new TexInfo(); ret.has_alpha = bitmap.HasAlpha; ret.needs_alpha_test = false; // ad-hock GLES20.GlPixelStorei(GLES20.GlUnpackAlignment, 1); int[] tex = new int[1]; GLES20.GlGenTextures(1, tex, 0); ret.tex = tex [0]; GLES20.GlBindTexture(GLES20.GlTexture2d, ret.tex); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinear); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0); bitmap.Recycle(); } return(ret); }
/// <summary> /// Create the shader program for label display in the openGL thread. /// This method will be called when WorldRenderManager's OnSurfaceCreated. /// </summary> /// <param name="labelBitmaps">View data indicating the plane type.</param> public void Init(List <Bitmap> labelBitmaps) { ShaderUtil.CheckGlError(TAG, "Init start."); if (labelBitmaps.Count == 0) { Log.Debug(TAG, "No bitmap."); } CreateProgram(); int idx = 0; GLES20.GlGenTextures(textures.Length, textures, 0); foreach (Bitmap labelBitmap in labelBitmaps) { // for semantic label plane GLES20.GlActiveTexture(GLES20.GlTexture0 + idx); GLES20.GlBindTexture(GLES20.GlTexture2d, textures[idx]); GLES20.GlTexParameteri( GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinearMipmapLinear); GLES20.GlTexParameteri( GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, labelBitmap, 0); GLES20.GlGenerateMipmap(GLES20.GlTexture2d); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); idx++; ShaderUtil.CheckGlError(TAG, "Texture loading"); } ShaderUtil.CheckGlError(TAG, "Init end."); }
//public synchronized void update(final GL10 pGL) { public void Update(GL10 pGL) { lock (_methodLock) { //final ArrayList<Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture; List <Letter> lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture; if (lettersPendingToBeDrawnToTexture.Count > 0) { int hardwareTextureID = this.mTexture.GetHardwareTextureID(); float textureWidth = this.mTextureWidth; float textureHeight = this.mTextureHeight; for (int i = lettersPendingToBeDrawnToTexture.Count - 1; i >= 0; i--) { Letter letter = lettersPendingToBeDrawnToTexture[i]; Bitmap bitmap = this.GetLetterBitmap(letter.mCharacter); GLHelper.BindTexture(pGL, hardwareTextureID); GLUtils.TexSubImage2D(GL10Consts.GlTexture2d, 0, (int)(letter.mTextureX * textureWidth), (int)(letter.mTextureY * textureHeight), bitmap); bitmap.Recycle(); } lettersPendingToBeDrawnToTexture.Clear(); //System.gc(); // TODO: Verify if this is a good match: System.gc() -> Dispose() ... leaving it to standard GC at present } } }
/// <summary> /// 加载位图生成纹理 /// </summary> /// <param name="gl"></param> private void loadTexture(IGL10 gl) { Bitmap bitmap = null; try { // 加载位图 bitmap = BitmapFactory.DecodeResource(ma.Resources, Resource.Drawable.sand); int[] textures = new int[1]; // 指定生成N个纹理(第一个参数指定生成一个纹理) // textures数组将负责存储所有纹理的代号 gl.GlGenTextures(1, textures, 0); // 获取textures纹理数组中的第一个纹理 texture = textures[0]; // 通知OpenGL将texture纹理绑定到GL10.GL_TEXTURE_2D目标中 gl.GlBindTexture(GL10.GlTexture2d, texture); // 设置纹理被缩小(距离视点很远时被缩小)时的滤波方式 gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureMinFilter, GL10.GlNearest); // 设置纹理被放大(距离视点很近时被方法)时的滤波方式 gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureMagFilter, GL10.GlLinear); // 设置在横向、纵向上都是平铺纹理 gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureWrapS, GL10.GlRepeat); gl.GlTexParameterf(GL10.GlTexture2d, GL10.GlTextureWrapT, GL10.GlRepeat); // 加载位图生成纹理 GLUtils.TexImage2D(GL10.GlTexture2d, 0, bitmap, 0); } finally { // 生成纹理之后,回收位图 if (bitmap != null) { bitmap.Recycle(); } } }
public void LoadTextures() { try { // Generate textures GLES20.GlGenTextures(2, MTextures, 0); // Load input bitmap if (MSourceBitmap != null) { MImageWidth = MSourceBitmap.Width; MImageHeight = MSourceBitmap.Height; MTexRenderer.UpdateTextureSize(MImageWidth, MImageHeight); // Upload to texture GLES20.GlBindTexture(GLES20.GlTexture2d, MTextures[0]); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, MSourceBitmap, 0); // Set texture parameters GlToolbox.InitTexParams(); } } catch (Exception e) { Console.WriteLine(e); } }
public virtual void Bitmap(Bitmap bitmap) { Bind(); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0); Premultiplied = true; }
public static int loadTexture(Context context, int resourceId) { if (resourceId == -1) { return(resourceId); } System.GC.Collect(); int[] textureHandle = new int[1]; GLES20.GlGenTextures(1, textureHandle, 0); if (textureHandle[0] != 0) { BitmapFactory.Options options = new BitmapFactory.Options(); options.InScaled = false; // No pre-scaling Bitmap bitmap = BitmapFactory.DecodeResource(context.Resources, resourceId, options); GLES20.GlBindTexture(GLES20.GlTexture2d, textureHandle[0]); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlNearest); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlNearest); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0); bitmap.Recycle(); } if (textureHandle[0] == 0) { throw new RuntimeException("Error loading texture."); } return(textureHandle[0]); }
public GLEx Update() { if (isClosed) { return(this); } if (batch != null) { GL20 gl = batch.gl; // 刷新原始设置 GLUtils.Reset(gl); // 清空背景为黑色 GLUtils.SetClearColor(gl, LColor.black); if (!LSystem.IsHTML5()) { // 禁用色彩抖动 GLUtils.DisableDither(gl); // 禁用深度测试 GLUtils.DisableDepthTest(gl); // 禁用双面剪切 GLUtils.DisableCulling(gl); } // 设定画布渲染模式为默认 this.SetBlendMode(BlendMethod.MODE_NORMAL); } return(this); }
public override void RenderTiles(TerrainMap map, ref int totalTriangles) { if (vboId == -1) { Console.WriteLine("Generating with colours!"); vboId = GLUtils.GenBuffer(); var sw = Stopwatch.StartNew(); Vertex[] vertices = BuildTerrain(map, ref triangles); long elapsed = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine("Took " + elapsed + " ms to generate the map."); int size = vertices.Length * 16; GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, vboId); GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, new IntPtr(size), vertices, BufferUsageArb.StaticDraw); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, 0); RenderColoursInfo(map); } GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, vboId); GL.VertexPointer(3, VertexPointerType.Float, 16, new IntPtr(0)); GL.ColorPointer(4, ColorPointerType.UnsignedByte, 16, new IntPtr(12)); GL.DrawArrays(BeginMode.Triangles, 0, triangles * 3); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.ColorArray); totalTriangles = triangles; }
protected override void BuildTerrainVbo(TerrainMap map) { fullVboId = GLUtils.GenBuffer(); Vertex[] fullVertices = new Vertex[map.Width * map.Length * PrimitiveElementSize]; vertices = fullVertices; BuildTerrain(map, ref triangles); fullVerticesCount = verticesCount; int size = fullVerticesCount * 16; GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, fullVboId); GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, new IntPtr(size), fullVertices, BufferUsageArb.StaticDraw); if (linesEnabled) { linesVboId = GLUtils.GenBuffer(); lineMode = true; Vertex[] lineVertices = new Vertex[map.Width * map.Length * PrimitiveElementSize]; vertices = lineVertices; BuildTerrain(map, ref triangles); size = verticesCount * 16; GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, linesVboId); GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, new IntPtr(size), lineVertices, BufferUsageArb.StaticDraw); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, 0); GL.LineWidth(2); } }
public override void RenderTiles(TerrainMap map, ref int totalTriangles) { if (fullVboId == -1) { Console.WriteLine("Generating with textures!"); fullVboId = GLUtils.GenBuffer(); var sw = Stopwatch.StartNew(); VertexPos3Tex2[] vertices = BuildTerrain(map, ref triangles); long elapsed = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine("Took " + elapsed + " ms to generate the map."); int size = vertices.Length * VertexPos3Tex2.Stride; GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, fullVboId); GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, new IntPtr(size), vertices, BufferUsageArb.StaticDraw); fullVerticesCount = vertices.Length; } GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, fullVboId); GL.VertexPointer(3, VertexPointerType.Float, VertexPos3Tex2.Stride, new IntPtr(0)); GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPos3Tex2.Stride, new IntPtr(12)); GL.DrawArrays(BeginMode.Quads, 0, fullVerticesCount); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.VertexArray); totalTriangles = triangles; }
public virtual GLEx SetBlendMode(int mode) { if (isClosed) { return(this); } lastBrush.blend = mode; GLUtils.SetBlendMode(batch.gl, mode); return(this); }
public override void initShader() { base.initShader(); //make texture ---------------------------------------------------- //draw texture if (LevelCanvas.b != null) { LevelCanvas.b.Recycle(); } int width = steps * textureStep; int height = steps * textureStep; Bitmap bitmap = Bitmap.CreateBitmap(width, height, Config.Argb8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.Color = Android.Graphics.Color.Green; paint.SetStyle(Paint.Style.Fill); canvas.DrawPaint(paint); paint.Color = Android.Graphics.Color.White; paint.AntiAlias = true; paint.TextSize = textureStep; paint.TextAlign = Paint.Align.Center; for (int i = 0; i < steps; i++) { paint.Color = Android.Graphics.Color.Rgb(i * 0xF, i * 0xF, i * 0xF); canvas.DrawText((steps - i).ToString(), textureStep + textureStep / 2, i * textureStep + textureStep - textureStep / 6, paint); } //load texture int[] textureHandle = new int[1]; GLES20.GlGenTextures(1, textureHandle, 0); if (textureHandle[0] != 0) { GLES20.GlBindTexture(GLES20.GlTexture2d, textureHandle[0]); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlNearest); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlNearest); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0); // bitmap.Recycle(); LevelCanvas.b = bitmap; } textureResID = textureHandle[0]; TextureManager.addTextureHandle(textureResID, textureHandle[0]); }
private IEnumerator __Start() { if (!this.configs.aSource) { this.configs.aSource = this.GetComponent <AudioSource>(); } if (!this.configs.aSource) { this.configs.aSource = this.GetComponentInChildren <AudioSource>(); } if (!this.configs.aSource) { this.configs.aSource = GameObject.FindObjectOfType(typeof(AudioSource)) as AudioSource; } if (!this.configs.aSource) { Debug.LogError("No Audio Source in the scene found to use for Sound Previews"); yield break; } if (this.configs.aSource.clip && this.enabled) { this.ResetClipView(this.configs.aSource.clip); } while (true) { yield return(new WaitForEndOfFrame()); if (!enabled) { continue; } if (this.configs.aSource.isPlaying) { GLUtils.RenderLines(this.vertices, this.configs.samplesColor); GLUtils.RenderVertices(this.viewers, this.configs.markersColor); GLUtils.RenderRect(this.GetFFTRect(), this.configs.bgColor, this.configs.borderColor); } bool stereo = this.verticesRight != null; GLUtils.RenderLines(this.verticesLeft, this.configs.samplesColor); GLUtils.RenderRect(this.GetLeftRect(stereo), this.configs.bgColor, this.configs.borderColor); if (stereo) { GLUtils.RenderLines(this.verticesRight, this.configs.samplesColor); GLUtils.RenderRect(this.GetRightRect(), this.configs.bgColor, this.configs.borderColor); } GLUtils.RenderLines(this.playingBar, this.configs.markersColor); } }
public override void RenderTiles(TerrainMap map, ref int totalTriangles) { if (fullVboId == -1) { Console.WriteLine("Generating with textures!"); fullVboId = GLUtils.GenBuffer(); linesVboId = GLUtils.GenBuffer(); var sw = Stopwatch.StartNew(); VertexPos3Tex2[] vertices = BuildTerrain(map, ref triangles); VertexPos3Col4[] lineVertices = BuildTerrainBorders(map, ref triangles); long elapsed = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine("Took " + elapsed + " ms to generate the map."); int size = vertices.Length * VertexPos3Tex2.Stride; GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, fullVboId); GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, new IntPtr(size), vertices, BufferUsageArb.StaticDraw); size = lineVertices.Length * VertexPos3Col4.Stride; GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, linesVboId); GL.Arb.BufferData(BufferTargetArb.ArrayBuffer, new IntPtr(size), lineVertices, BufferUsageArb.StaticDraw); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, 0); fullVerticesCount = vertices.Length; lineVerticesCount = lineVertices.Length; GL.LineWidth(5); } GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.Arb.BindBuffer(BufferTargetArb.ArrayBuffer, fullVboId); GL.VertexPointer(3, VertexPointerType.Float, VertexPos3Tex2.Stride, new IntPtr(0)); GL.TexCoordPointer(2, TexCoordPointerType.Float, VertexPos3Tex2.Stride, new IntPtr(12)); GL.DrawArrays(BeginMode.Quads, 0, fullVerticesCount); GL.DisableClientState(ArrayCap.TextureCoordArray); /*GL.EnableClientState( ArrayCap.ColorArray ); * * GL.PolygonMode( MaterialFace.FrontAndBack, PolygonMode.Line ); * GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, linesVboId ); * GL.VertexPointer( 3, VertexPointerType.Float, VertexPos3Col4.Stride, new IntPtr( 0 ) ); * GL.ColorPointer( 4, ColorPointerType.UnsignedByte, VertexPos3Col4.Stride, new IntPtr( 12 ) ); * GL.DrawArrays( BeginMode.Quads, 0, lineVerticesCount ); * GL.PolygonMode( MaterialFace.FrontAndBack, PolygonMode.Fill ); * * GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 ); * GL.DisableClientState( ArrayCap.ColorArray );*/ GL.DisableClientState(ArrayCap.VertexArray); totalTriangles = triangles; }
private Texture(String filename) { #if __ANDROID__ AssetManager assets = GameActivity.Instance.Assets; Bitmap bitmap = null; using (Stream stream = assets.Open(filename)) { bitmap = BitmapFactory.DecodeStream(stream); Width = bitmap.Width; Height = bitmap.Height; } GL.GenTextures(1, out _GLID); GL.BindTexture(All.Texture2D, _GLID); GL.TexParameter(All.Texture2D, All.TextureWrapS, (Int32)All.Repeat); GL.TexParameter(All.Texture2D, All.TextureWrapT, (Int32)All.Repeat); GL.TexParameter(All.Texture2D, All.TextureMinFilter, (Int32)All.Linear); GL.TexParameter(All.Texture2D, All.TextureMagFilter, (Int32)All.Linear); GLUtils.TexImage2D((Int32)All.Texture2D, 0, bitmap, 0); GL.GenerateMipmap(All.Texture2D); GL.BindTexture(All.Texture2D, 0); bitmap.Recycle(); #elif __IOS__ UIImage image = UIImage.FromFile(filename); nint cgWidth = image.CGImage.Width; nint cgHeight = image.CGImage.Height; Width = (Int32)cgWidth; Height = (Int32)cgHeight; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); Byte[] data = new Byte[Width * Height * 4]; CGContext context = new CGBitmapContext(data, cgWidth, cgHeight, 8, 4 * Width, colorSpace, CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrderDefault); colorSpace.Dispose(); context.ClearRect(new CGRect(0, 0, cgWidth, cgHeight)); context.DrawImage(new CGRect(0, 0, cgWidth, cgHeight), image.CGImage); GL.GenTextures(1, out _GLID); GL.BindTexture(TextureTarget.Texture2D, _GLID); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (Int32)All.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (Int32)All.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (Int32)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (Int32)TextureMagFilter.Linear); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data); context.Dispose(); GL.GenerateMipmap(TextureTarget.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); #endif LoadedTextures.Add(filename, this); _Filename = filename; }
/// <summary> /// Initialize the OpenGL ES rendering related to face geometry, /// including creating the shader program. /// This method is called when FaceRenderManager's OnSurfaceCreated method calling. /// </summary> /// <param name="context">Context.</param> public void Init(Context context) { ShaderUtil.CheckGlError(TAG, "Init start."); int[] texNames = new int[1]; GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlGenTextures(1, texNames, 0); mTextureName = texNames[0]; int[] buffers = new int[BUFFER_OBJECT_NUMBER]; GLES20.GlGenBuffers(BUFFER_OBJECT_NUMBER, buffers, 0); mVerticeId = buffers[0]; mTriangleId = buffers[1]; GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVerticeId); GLES20.GlBufferData(GLES20.GlArrayBuffer, mVerticeBufferSize * BYTES_PER_POINT, null, GLES20.GlDynamicDraw); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mTriangleId); // Each floating-point number occupies 4 bytes. GLES20.GlBufferData(GLES20.GlElementArrayBuffer, mTriangleBufferSize * 4, null, GLES20.GlDynamicDraw); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextureName); CreateProgram(); //Add texture to facegeometry. Bitmap textureBitmap = null; AssetManager assets = context.Assets; try { Stream sr = assets.Open("face_geometry.png"); textureBitmap = BitmapFactory.DecodeStream(sr); } catch (Exception e) { Log.Debug(TAG, " Open bitmap error!"); } GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinearMipmapLinear); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, textureBitmap, 0); GLES20.GlGenerateMipmap(GLES20.GlTexture2d); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); ShaderUtil.CheckGlError(TAG, "Init end."); }
public virtual int CreateTexture(LTexture.Format config, int count) { int id = gl.GLGenTexture() + count; GLUtils.BindTexture(gl, id); GLUtils.BindTexture(gl, id); gl.GLTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, config.magFilter); int minFilter = Mipmapify(config.minFilter, config.mipmaps); gl.GLTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter); gl.GLTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, config.repeatX ? GL.GL_REPEAT : GL.GL_CLAMP_TO_EDGE); gl.GLTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, config.repeatY ? GL.GL_REPEAT : GL.GL_CLAMP_TO_EDGE); return(id); }
protected void GenerateTexture(Bitmap bitmap) { GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Fastest); uint name = (uint)GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, name); /* TODO is this needed? * if (GLExtensions.TextureMaxAnisotropySupported) * { * float maxAniso; * GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out maxAniso); * GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, maxAniso); * } */ GL.TexStorage2D(TextureTarget2D.Texture2D, 1, // mipmap level, min 1 SizedInternalFormat.Rgba8, bitmap.Width, bitmap.Height); if (bitmap.Width > 0 && bitmap.Height > 0) { GLUtils.TexSubImage2D(GLES20.GlTexture2d, 0, // level 0, // xOffset 0, // yOffset bitmap); } else { Console.Out.WriteLine("WARNING: empty bitmap loaded"); } // see https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Texture2D.OpenGL.cs // for how MonoGame does it _glTexture = new GLTexture(name, bitmap.Width, bitmap.Height, false, 1.0f, false); _isLoaded = true; // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. EventHandler <GLTexture> handler = ResourceLoaded; if (handler != null) { handler(this, _glTexture); } }
protected override int CreateTexture(Bitmap bmp, bool filter) { var id = new int[1]; GLES11.GlGenTextures(1, id, 0); GLES11.GlBindTexture(GLES11.GlTexture2d, id[0]); GLUtils.TexImage2D(GLES11.GlTexture2d, 0, bmp, 0); GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureMinFilter, filter ? GLES11.GlLinear : GLES11.GlNearest); GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureMagFilter, filter ? GLES11.GlLinear : GLES11.GlNearest); GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapS, GLES11.GlClampToEdge); GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapT, GLES11.GlClampToEdge); bmp.Recycle(); return(id[0]); }
private void doCoordinatePicking() { if (pickingActive && !MapView.MapIsEnabled) { pickingActive = false; close(); } CelestialBody body = PlanetariumCamera.fetch.target.celestialBody; if (body == null) { Vessel vessel = PlanetariumCamera.fetch.target.vessel; if (vessel != null) { body = vessel.getCurrentBody().getCelestialBody(); } } if (body == null) { pickingActive = false; } if (!pickingActive) { return; } Coordinates mouseCoords = GuiUtils.GetMouseCoordinates(body); if (this.coords != null) { GLUtils.DrawMapViewGroundMarker(body, this.coords.latitude, this.coords.longitude, radius, Color.red); double distance = getDistance(this.coords, mouseCoords, body); infoWindow.text = this.coords.ToStringDecimal() + "\nDistance: " + distance.ToString("F1") + " m"; } if (mouseCoords != null) { GLUtils.DrawMapViewGroundMarker(body, mouseCoords.latitude, mouseCoords.longitude, body.Radius / 15, Color.yellow); if (Input.GetMouseButtonDown(0)) { this.coords = mouseCoords; } } }
public virtual GLEx Reset(float red, float green, float blue, float alpha) { if (isClosed) { return(this); } GLUtils.SetClearColor(batch.gl, red, green, blue, alpha); this.SetFont(LSystem.GetSystemGameFont()); this.lastBrush.baseColor = LColor.DEF_COLOR; this.lastBrush.fillColor = LColor.DEF_COLOR; this.lastBrush.baseAlpha = 1f; this.lastBrush.patternTex = null; this.SetBlendMode(BlendMethod.MODE_NORMAL); this.ResetLineWidth(); return(this); }
/// <summary> /// Allocates and initializes OpenGL resources needed by the plane renderer. Must be /// called on the OpenGL thread, typically in /// <see cref="GLSurfaceView.IRenderer.OnSurfaceCreated(IGL10, Javax.Microedition.Khronos.Egl.EGLConfig)"/> /// </summary> /// <param name="context">Needed to access shader source and texture PNG.</param> /// <param name="gridDistanceTextureName">Name of the PNG file containing the grid texture.</param> public void CreateOnGlThread(Context context, String gridDistanceTextureName) { int vertexShader = ShaderUtil.LoadGLShader(TAG, context, GLES20.GlVertexShader, Resource.Raw.plane_vertex); int passthroughShader = ShaderUtil.LoadGLShader(TAG, context, GLES20.GlFragmentShader, Resource.Raw.plane_fragment); mPlaneProgram = GLES20.GlCreateProgram(); GLES20.GlAttachShader(mPlaneProgram, vertexShader); GLES20.GlAttachShader(mPlaneProgram, passthroughShader); GLES20.GlLinkProgram(mPlaneProgram); GLES20.GlUseProgram(mPlaneProgram); ShaderUtil.CheckGLError(TAG, "Program creation"); // Read the texture. var textureBitmap = Android.Graphics.BitmapFactory.DecodeStream( context.Assets.Open(gridDistanceTextureName)); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlGenTextures(mTextures.Length, mTextures, 0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinearMipmapLinear); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, textureBitmap, 0); GLES20.GlGenerateMipmap(GLES20.GlTexture2d); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); ShaderUtil.CheckGLError(TAG, "Texture loading"); mPlaneXZPositionAlphaAttribute = GLES20.GlGetAttribLocation(mPlaneProgram, "a_XZPositionAlpha"); mPlaneModelUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_Model"); mPlaneModelViewProjectionUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_ModelViewProjection"); mTextureUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_Texture"); mLineColorUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_lineColor"); mDotColorUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_dotColor"); mGridControlUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_gridControl"); mPlaneUvMatrixUniform = GLES20.GlGetUniformLocation(mPlaneProgram, "u_PlaneUvMatrix"); ShaderUtil.CheckGLError(TAG, "Program parameters"); }
public Texture(Bitmap bitmap) { bitmap = ReverseBitmap(bitmap); Width = bitmap.Width; Height = bitmap.Height; GL.GenTextures(1, out int code); TextureCode = code; Bind(); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); GLUtils.TexImage2D((int)TextureTarget.Texture2D, 0, bitmap, 0); GL.GenerateMipmap(TextureTarget.Texture2D); }
protected override void Initialize() { _glesTexture = GLUtils.LoadTexture("opengles.png"); _smileyTexture = GLUtils.LoadTexture("smiley.png"); ; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); var random = new Random(); for (int i = 0; i < _smileys.Length; i++) { _smileys[i].SrcWidth = 128; _smileys[i].SrcHeight = 128; switch (random.Next(4)) { case 0: _smileys[i].SrcX = 0; _smileys[i].SrcY = 0; break; case 1: _smileys[i].SrcX = 128; _smileys[i].SrcY = 0; break; case 2: _smileys[i].SrcX = 0; _smileys[i].SrcY = 128; break; case 3: _smileys[i].SrcX = 128; _smileys[i].SrcY = 128; break; } _smileys[i].Position = new Vector2(random.Next(WindowWidth), random.Next(WindowHeight)); _smileys[i].Tint = new Vector4( (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); } }
protected override void Initialize() { string vertShader = @"attribute vec3 vertPosition; attribute vec3 vertColor; varying vec3 fragColor; void main() { gl_Position = vec4(vertPosition, 1.0); fragColor = vertColor; }"; string fragShader = @"precision mediump float; varying vec3 fragColor; void main() { gl_FragColor = vec4(fragColor, 1.0); }"; uint vertexShader = GLUtils.CompileShader(vertShader, GL_VERTEX_SHADER); uint fragmentShader = GLUtils.CompileShader(fragShader, GL_FRAGMENT_SHADER); _program = glCreateProgram(); if (_program == 0) { throw new InvalidOperationException("Failed to create program."); } glAttachShader(_program, vertexShader); glAttachShader(_program, fragmentShader); glBindAttribLocation(_program, 0, "vertPosition"); glBindAttribLocation(_program, 1, "vertColor"); GLUtils.LinkProgram(_program); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); }
public static Texture2D GetTexture(InterpolationMode interpolation, params string[] path) { int pathhash = path.GetHashCode( ); if (!textureCache.ContainsKey(pathhash) || textureCache[pathhash].Disposed) { int width, height, id = GL.GenTexture( ); GL.BindTexture(TextureTarget.Texture2D, id); #if __ANDROID__ using (BitmapFactory.Options options = new BitmapFactory.Options( ) { InScaled = false }) using (Stream stream = GetStream(path)) using (Bitmap bitmap = BitmapFactory.DecodeStream(stream, null, options)) { GLUtils.TexImage2D((int)TextureTarget.Texture2D, 0, bitmap, 0); width = bitmap.Width; height = bitmap.Height; } #endif GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)interpolation); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)interpolation); if (!textureCache.ContainsKey(pathhash)) { textureCache.Add(pathhash, new Texture2D(id, new Size(width, height), path[path.Length - 1])); } else { textureCache[pathhash] = new Texture2D(id, new Size(width, height), path[path.Length - 1]); } #if DEBUG if (id == 0 || Debug.CheckGL(typeof(Assets))) { Debug.Print(typeof(Assets), "failed loading image " + path[path.Length - 1]); } else { Debug.Print(typeof(Assets), "loaded image " + path[path.Length - 1]); } #endif } return(textureCache[pathhash]); }
public GLBitmapAtlas CreateBitmapAtlasFromResources(string[] names) { var bitmaps = new Bitmap[names.Length]; var elementSizeX = 0; var elementSizeY = 0; for (int i = 0; i < names.Length; i++) { var bmp = LoadBitmapFromResourceWithScaling(names[i]); elementSizeX = Math.Max(elementSizeX, bmp.Width); elementSizeY = Math.Max(elementSizeY, bmp.Height); bitmaps[i] = bmp; } var elementsPerRow = MaxAtlasResolution / elementSizeX; var numRows = Utils.DivideAndRoundUp(names.Length, elementsPerRow); var atlasSizeX = elementsPerRow * elementSizeX; var atlasSizeY = numRows * elementSizeY; var textureId = CreateEmptyTexture(atlasSizeX, atlasSizeY, true); var elementRects = new Rectangle[names.Length]; GLES11.GlBindTexture(GLES11.GlTexture2d, textureId); for (int i = 0; i < names.Length; i++) { var bmp = bitmaps[i]; var row = i / elementsPerRow; var col = i % elementsPerRow; elementRects[i] = new Rectangle( col * elementSizeX, row * elementSizeY, bmp.Width, bmp.Height); GLUtils.TexSubImage2D(GLES11.GlTexture2d, 0, elementRects[i].X, elementRects[i].Y, bmp); bmp.Recycle(); } return(new GLBitmapAtlas(textureId, atlasSizeX, atlasSizeY, elementRects, true, true)); }
private void SetupImage() { // Create our UV coordinates. uvs = new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f }; // The texture buffer ByteBuffer byteBuffer = ByteBuffer.AllocateDirect(uvs.Length * 4); byteBuffer.Order(ByteOrder.NativeOrder()); uvBuffer = byteBuffer.AsFloatBuffer(); uvBuffer.Put(uvs); uvBuffer.Position(0); // Generate Textures, if more needed, alter these numbers. int[] textureIds = new int[1]; GLES20.GlGenTextures(1, textureIds, 0); // Retrieve our image from resources. Bitmap bitmap = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.plant07); // Bind texture to texturename GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, textureIds[0]); // Set filtering GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinear); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); // Set wrapping mode GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); // Load the bitmap into the bound texture. GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0); // We are done using the bitmap so we should recycle it. bitmap.Recycle(); bitmap.Dispose(); }