protected override void OnReadyForInitGLShaderProgram() { //---------------- //vertex shader source string vs = @" attribute vec4 vPosition; void main() { gl_Position = vPosition; } "; //fragment source string fs = @" precision mediump float; void main() { gl_FragColor = vec4(1.0,0.0, 0.0, 1.0); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { //return false } GL.ClearColor(0, 0, 0, 0); }
protected override void OnReadyForInitGLShaderProgram() { string vs = @" uniform float u_offset; attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = a_position; gl_Position.x += u_offset; v_texCoord = a_texCoord; } "; string fs = @" precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { gl_FragColor = texture2D(s_texture, v_texCoord); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { //error throw new NotSupportedException(); } //mProgram = CompileProgram(vs, fs); //if (!mProgram) //{ // return false; //} //// Get the attribute locations //mPositionLoc = glGetAttribLocation(mProgram, "a_position"); //mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord"); mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord"); //// Get the sampler location //mSamplerLoc = glGetUniformLocation(mProgram, "s_texture"); mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture"); //// Get the offset location //mOffsetLoc = glGetUniformLocation(mProgram, "u_offset"); mOffsetLoc = GL.GetUniformLocation(mProgram, "u_offset"); //// Load the texture mTexture = ES2Utils2.CreateMipMappedTexture2D(); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.ClearColor(0, 0, 0, 0); isGLInit = true; this.EnableAnimationTimer = true; }
protected override void OnReadyForInitGLShaderProgram() { string vs = @" uniform float u_offset; attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = a_position; gl_Position.x += u_offset; v_texCoord = a_texCoord; } "; string fs = @" precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { gl_FragColor = texture2D(s_texture, v_texCoord); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { throw new NotSupportedException(); } //// Get the attribute locations //mPositionLoc = glGetAttribLocation(mProgram, "a_position"); mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); //mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord"); //// Get the sampler location //mSamplerLoc = glGetUniformLocation(mProgram, "s_texture"); mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture"); //// Get the offset location //mOffsetLoc = glGetUniformLocation(mProgram, "u_offset"); mOffsetLoc = GL.GetUniformLocation(mProgram, "u_offset"); //// Load the texture //mTextureID = CreateMipMappedTexture2D(); mTextureID = ES2Utils2.CreateMipMappedTexture2D(); //// Check Anisotropy limits //glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mMaxAnisotropy); GL.GetFloat((GetPName)(ExtTextureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY), out mMaxAnisotropy); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.ClearColor(0, 0, 0, 0); isGLInit = true; this.EnableAnimationTimer = true; }
protected override void OnReadyForInitGLShaderProgram() { string vs = @" attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = a_position; v_texCoord = a_texCoord; } "; string fs = @" precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_baseMap; uniform sampler2D s_lightMap; void main() { vec4 baseColor; vec4 lightColor; baseColor = texture2D(s_baseMap, v_texCoord); lightColor = texture2D(s_lightMap, v_texCoord); gl_FragColor = baseColor * (lightColor + 0.25); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { throw new NotSupportedException(); } // Get the attribute locations mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord"); // Get the sampler location mBaseMapLoc = GL.GetUniformLocation(mProgram, "s_baseMap"); mLightMapLoc = GL.GetUniformLocation(mProgram, "s_lightMap"); // Load the textures mBaseMapTexID = LoadTexture(RootDemoPath.Path + @"\SampleImages\basemap01.png"); mLightMapTexID = LoadTexture(RootDemoPath.Path + @"\SampleImages\lightmap01.png"); if (mBaseMapTexID == 0 || mLightMapTexID == 0) { throw new NotSupportedException(); } isGLInit = true; this.EnableAnimationTimer = true; }
protected override void OnReadyForInitGLShaderProgram() { string vs = @" attribute vec4 a_position; void main() { gl_Position = a_position; } "; string fs = @" precision mediump float; uniform vec4 u_color; void main() { gl_FragColor = u_color; } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { throw new NotSupportedException(); } //// Get the attribute locations //mPositionLoc = glGetAttribLocation(mProgram, "a_position"); mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); //// Get the sampler location //mColorLoc = glGetUniformLocation(mProgram, "u_color"); mColorLoc = GL.GetUniformLocation(mProgram, "u_color"); //// Set the clear color //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.ClearColor(0, 0, 0, 0); //// Set the stencil clear value //glClearStencil(0x01); GL.ClearStencil(0x01); //// Set the depth clear value //glClearDepthf(0.75f); GL.ClearDepth(0.75f); //// Enable the depth and stencil tests //glEnable(GL_DEPTH_TEST); GL.Enable(EnableCap.DepthTest); //glEnable(GL_STENCIL_TEST); GL.Enable(EnableCap.StencilTest); //return true; isGLInit = true; this.EnableAnimationTimer = true; }
protected override void OnReadyForInitGLShaderProgram() { string vs = @" uniform mat4 u_mvpMatrix; attribute vec4 a_position; attribute vec2 a_texcoord; varying vec2 v_texcoord; void main() { gl_Position = u_mvpMatrix * a_position; v_texcoord = a_texcoord; } "; string fs = @" precision mediump float; varying vec2 v_texcoord; void main() { gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { //return false throw new NotSupportedException(); } //GL.Enable(EnableCap.Blend); //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // Get the attribute locations mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texcoord"); // Get the uniform locations mMVPMatrixLoc = GL.GetUniformLocation(mProgram, "u_mvpMatrix"); cube = new CubeGeometry(); GeometryUtils.GenerateCubeGeometry(-0.5f, cube); mRotation = 45.0f; GL.ClearColor(0, 0, 0, 0); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.CullFace); this.EnableAnimationTimer = true; isGLInit = true; }
protected override void OnReadyForInitGLShaderProgram() { //-------------------------------------------------------------------------- string vs = @" attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = a_position; v_texCoord = a_texCoord; } "; string fs = @" precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { gl_FragColor = texture2D(s_texture, v_texCoord); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { //return false } // Get the attribute locations mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord"); // Get the sampler location mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture"); //// Load the texture mTexture = ES2Utils2.CreateSimpleTexture2D(); GL.ClearColor(0, 0, 0, 0); //================================================================================ }
protected override void OnReadyForInitGLShaderProgram() { IntPtr eglPostSubBufferNVFuncPtr = OpenTK.Platform.Egl.Egl.GetProcAddress("eglPostSubBufferNV"); if (eglPostSubBufferNVFuncPtr == IntPtr.Zero) { throw new NotSupportedException(); } mPostSubBufferNV = (PFNEGLPOSTSUBBUFFERNVPROC)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(eglPostSubBufferNVFuncPtr, typeof(PFNEGLPOSTSUBBUFFERNVPROC)); // mPostSubBufferNV = (PFNEGLPOSTSUBBUFFERNVPROC)eglGetProcAddress("eglPostSubBufferNV"); //if (!mPostSubBufferNV) //{ // std::cerr << "Could not load eglPostSubBufferNV."; // return false; //} string vs = @" uniform mat4 u_mvpMatrix; attribute vec4 a_position; attribute vec2 a_texcoord; varying vec2 v_texcoord; void main() { gl_Position = u_mvpMatrix * a_position; v_texcoord = a_texcoord; } "; string fs = @" precision mediump float; varying vec2 v_texcoord; void main() { gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0); } "; //mProgram = CompileProgram(vs, fs); //if (!mProgram) //{ // return false; //} mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { throw new NotSupportedException(); } //// Get the attribute locations //mPositionLoc = glGetAttribLocation(mProgram, "a_position"); mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); //mTexcoordLoc = glGetAttribLocation(mProgram, "a_texcoord"); mTexcoordLoc = GL.GetAttribLocation(mProgram, "a_texcoord"); //// Get the uniform locations //mMVPMatrixLoc = glGetUniformLocation(mProgram, "u_mvpMatrix"); mMVPMatrixLoc = GL.GetUniformLocation(mProgram, "u_mvpMatrix"); //// Generate the geometry data //GenerateCubeGeometry(0.5f, &mCube); mCube = new CubeGeometry(); GeometryUtils.GenerateCubeGeometry(0.5f, mCube); //// Set an initial rotation //mRotation = 45.0f; mRotation = 45.0f; //// Clear the whole window surface to blue. //glClearColor(0.0f, 0.0f, 1.0f, 0.0f); GL.ClearColor(0, 0, 1, 0); //glClear(GL_COLOR_BUFFER_BIT); GL.Clear(ClearBufferMask.ColorBufferBit); //SampleApplication::swap(); //this.miniGLControl.SwapBuffers(); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.ClearColor(0, 0, 0, 0); //glCullFace(GL_BACK); GL.CullFace(CullFaceMode.Back); //glEnable(GL_CULL_FACE); GL.Enable(EnableCap.CullFace); //return true; isGLInit = true; this.EnableAnimationTimer = true; }
protected override void OnReadyForInitGLShaderProgram() { //-------------------------------------------------------------------------- string vs = @" attribute vec4 a_position; attribute vec2 a_texCoord; uniform mat4 u_mvpMatrix; varying vec2 v_texCoord; void main() { gl_Position = u_mvpMatrix* a_position; v_texCoord = a_texCoord; } "; //in fs, angle on windows //we need to switch color component //because we store value in memory as BGRA //and gl expect input in RGBA string fs = @" precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { vec4 c = texture2D(s_texture, v_texCoord); gl_FragColor = vec4(c[2],c[1],c[0],c[3]); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { //return false } // Get the attribute locations mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord"); u_matrix = GL.GetUniformLocation(mProgram, "u_mvpMatrix"); // Get the sampler location mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture"); //// Load the texture PixelFarm.CpuBlit.MemBitmap bmp = PixelFarm.CpuBlit.MemBitmapExt.LoadBitmap(RootDemoPath.Path + @"\lion1.png"); int bmpW = bmp.Width; int bmpH = bmp.Height; mTexture = LoadTexture(bmp); GL.ClearColor(0, 0, 0, 0); //================================================================================ GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(1, 1, 1, 1); //setup viewport size int max = Math.Max(this.Width, this.Height); orthoViewMat = MyMat4.ortho(0, max, 0, max, 0, 1).data; //square viewport GL.Viewport(0, 0, max, max); imgVertices = new float[] { 0, bmpH, 0, 0, 0, //--------------------- 0, 0, 0, 0, 1, //--------------------- bmpW, bmpH, 0, 1, 0, //--------------------- bmpW, 0, 0, 1, 1 }; }
protected override void OnReadyForInitGLShaderProgram() { string vs = @" uniform float u_offset; attribute vec4 a_position; attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = a_position; gl_Position.x += u_offset; v_texCoord = a_texCoord; } "; string fs = @" precision mediump float; varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { gl_FragColor = texture2D(s_texture, v_texCoord); } "; mProgram = EsUtils.CompileProgram(vs, fs); if (mProgram == 0) { //error throw new NotSupportedException(); } //mProgram = CompileProgram(vs, fs); //if (!mProgram) //{ // return false; //} //// Get the attribute locations //mPositionLoc = glGetAttribLocation(mProgram, "a_position"); //mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord"); mPositionLoc = GL.GetAttribLocation(mProgram, "a_position"); mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord"); //// Get the sampler location //mSamplerLoc = glGetUniformLocation(mProgram, "s_texture"); mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture"); //// Get the offset location //mOffsetLoc = glGetUniformLocation(mProgram, "u_offset"); mOffsetLoc = GL.GetUniformLocation(mProgram, "u_offset"); //// Load the texture mTexture = ES2Utils2.CreateMipMappedTexture2D(); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.ClearColor(0, 0, 0, 0); isGLInit = true; this.EnableAnimationTimer = true; //create vbo array float[] vertices = new float[] { -0.3f, 0.3f, 0.0f, 1.0f, // Position 0 -1.0f, -1.0f, // TexCoord 0 -0.3f, -0.3f, 0.0f, 1.0f, // Position 1 -1.0f, 2.0f, // TexCoord 1 0.3f, -0.3f, 0.0f, 1.0f, // Position 2 2.0f, 2.0f, // TexCoord 2 0.3f, 0.3f, 0.0f, 1.0f, // Position 3 2.0f, -1.0f // TexCoord 3 }; //GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; ushort[] indices = new ushort[] { 0, 1, 2, 0, 2, 3 }; vbo2 = new PixelFarm.DrawingGL.VertexBufferObject(); vbo2.CreateBuffers(vertices, indices); }