protected override void DrawData(DrawInfo drawInfo, IDrawableState state) { texture.Bind(); vertexes.Bind(); Gl.glVertexPointer(Vector2D.Count, GlHelper.GlScalar, 0, IntPtr.Zero); coordinates.Bind(); Gl.glTexCoordPointer(Vector2D.Count, GlHelper.GlScalar, 0, IntPtr.Zero); // GlHelper.GlColor4(color.Red, color.Green, color.Blue, color.Alpha); Gl.glDrawArrays(Gl.GL_QUADS, 0, vertexes.Length); }
protected override void DrawData(DrawInfo drawInfo, IDrawableState state) { // Set The First Texture Unit To Normalize Our Vector From The Surface To The Light. // Set The Texture Environment Of The First Texture Unit To Replace It With The // Sampled Value Of The Normalization Cube Map. Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY); vertexes.Bind(); //Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, vertexName); Gl.glVertexPointer(Vector2D.Count, GlHelper.GlScalar, 0, IntPtr.Zero); Gl.glActiveTextureARB(Gl.GL_TEXTURE0_ARB); Gl.glClientActiveTexture(Gl.GL_TEXTURE0_ARB); Gl.glEnable(Gl.GL_TEXTURE_CUBE_MAP); Gl.glBindTexture(Gl.GL_TEXTURE_CUBE_MAP, normalization_cube_map); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_COMBINE); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_COMBINE_RGB, Gl.GL_REPLACE); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE0_RGB, Gl.GL_TEXTURE); Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); vertexes.Bind(); //Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, vertexName); Gl.glTexCoordPointer(Vector2D.Count, GlHelper.GlScalar, 0, IntPtr.Zero); //now we change the textures origin to that of the light's position GlHelper.GlGetModelViewMatrix(GlMatrix); Matrix4x4 matrix; Matrix4x4.CopyTranspose(GlMatrix, out matrix); Matrix4x4.Invert(ref matrix, out matrix); Vector3D lightPos; Vector3D.Transform(ref matrix, ref light.Position, out lightPos); Gl.glMatrixMode(Gl.GL_TEXTURE); Gl.glLoadIdentity(); GlHelper.GlScale(-1, -1, -1); GlHelper.GlTranslate( (xInverted) ? (lightPos.X) : (-lightPos.X), (yInverted) ? (lightPos.Y) : (-lightPos.Y), -lightPos.Z); // Set The Second Unit To The Bump Map. // Set The Texture Environment Of The Second Texture Unit To Perform A Dot3 // Operation With The Value Of The Previous Texture Unit (The Normalized // Vector Form The Surface To The Light) And The Sampled Texture Value (The // Normalized Normal Vector Of Our Bump Map). Gl.glActiveTextureARB(Gl.GL_TEXTURE1_ARB); Gl.glClientActiveTexture(Gl.GL_TEXTURE1_ARB); Gl.glEnable(Gl.GL_TEXTURE_2D); bumpmap.Bind(); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_COMBINE); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_COMBINE_RGB, Gl.GL_DOT3_RGB); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE0_RGB, Gl.GL_PREVIOUS); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_SOURCE1_RGB, Gl.GL_TEXTURE); Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); coordinates.Bind(); Gl.glTexCoordPointer(Vector2D.Count, GlHelper.GlScalar, 0, IntPtr.Zero); // Set The Third Texture Unit To Our Texture. // Set The Texture Environment Of The Third Texture Unit To Modulate // (Multiply) The Result Of Our Dot3 Operation With The Texture Value. Gl.glActiveTextureARB(Gl.GL_TEXTURE2_ARB); Gl.glClientActiveTexture(Gl.GL_TEXTURE2_ARB); Gl.glEnable(Gl.GL_TEXTURE_2D); sprite.Bind(); Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_MODULATE); Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); coordinates.Bind(); Gl.glTexCoordPointer(Vector2D.Count, GlHelper.GlScalar, 0, IntPtr.Zero); //THEN YOU DRAW IT! MUAHHAAHA IT WORKS! it finally works! Gl.glDrawArrays(Gl.GL_QUADS, 0, 4); Gl.glDisable(Gl.GL_TEXTURE_2D); Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glActiveTextureARB(Gl.GL_TEXTURE1_ARB); Gl.glClientActiveTexture(Gl.GL_TEXTURE1_ARB); Gl.glDisable(Gl.GL_TEXTURE_2D); Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glActiveTextureARB(Gl.GL_TEXTURE0_ARB); Gl.glClientActiveTexture(Gl.GL_TEXTURE0_ARB); Gl.glDisable(Gl.GL_TEXTURE_CUBE_MAP); Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY); Gl.glLoadIdentity(); Gl.glMatrixMode(Gl.GL_MODELVIEW); }