Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
attribute vec4 a_position; attribute vec2 a_texcoord; varying vec2 v_texcoord; void main() { v_texcoord = a_texcoord.st; gl_Position = a_position; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
varying vec2 v_texcoord; uniform sampler2D u_texture_y; void main() { vec4 color; color.rgba = texture2D(u_texture_y, v_texcoord).rgba; gl_FragColor = color; } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
private void CreateShaders(byte[] vsFile, byte[] fsFile, out int vertexObject, out int fragmentObject, out int program) { int status_code; string info; // Read shader files string vs = System.Text.Encoding.UTF8.GetString( DaltonEyes.Properties.Resources.testVertexShader); string fs = System.Text.Encoding.UTF8.GetString( DaltonEyes.Properties.Resources.testFragmentShader); // Setup shader objects vertexObject = GL.CreateShader(ShaderType.VertexShader); fragmentObject = GL.CreateShader(ShaderType.FragmentShader); // Compile vertex shader GL.ShaderSource(vertexObject, vs); GL.CompileShader(vertexObject); GL.GetShaderInfoLog(vertexObject, out info); GL.GetShader(vertexObject, ShaderParameter.CompileStatus, out status_code); if (status_code != 1) { throw new ApplicationException(info); } // Compile vertex shader GL.ShaderSource(fragmentObject, fs); GL.CompileShader(fragmentObject); GL.GetShaderInfoLog(fragmentObject, out info); GL.GetShader(fragmentObject, ShaderParameter.CompileStatus, out status_code); if (status_code != 1) { throw new ApplicationException(info); } program = GL.CreateProgram(); GL.AttachShader(program, fragmentObject); GL.AttachShader(program, vertexObject); GL.LinkProgram(program); float[] vertexVertices = { -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f }; float[] textureVertices = { 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; int handleAPosition = GL.GetAttribLocation(program, "a_position"); int handleATexcoord = GL.GetAttribLocation(program, "a_texcoord"); GL.EnableVertexAttribArray(handleAPosition); GL.EnableVertexAttribArray(handleATexcoord); GL.VertexAttribPointer(handleAPosition, 2, VertexAttribPointerType.Float, false, 0, vertexVertices); GL.VertexAttribPointer(handleATexcoord, 2, VertexAttribPointerType.Float, false, 0, textureVertices); GL.UseProgram(program); } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public int LoadTexture(Bitmap bitmap) { int tex; GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.GenTextures(1, out tex); GL.BindTexture(TextureTarget.Texture2D, tex); BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); bitmap.UnlockBits(data); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); return tex; } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
int vertexShaderObject, fragmentShaderObject, shaderProgram; int vertexBufferObject, colorBufferObject, elementBufferObject; int currentTextureId; private void InitTexturing() { GL.Disable(EnableCap.CullFace); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); } private void SetupViewport() { int w = glControl1.Width; int h = glControl1.Height; GL.ClearColor(Color.Black); GL.MatrixMode(MatrixMode.Modelview); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, w, 0, h, -1, 1); // Bottom-left corner pixel has coordinate (0,0) GL.Viewport(0, 0, w, h); // Use all of the glControl paintining area } private void OnLoadGL(object sender, EventArgs e) { this.GLContextLoaded = true; this.SetupViewport(); this.InitTexturing(); } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
public void DrawImage(int image) { int w = glControl1.Width; int h = glControl1.Height; GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); GL.Disable(EnableCap.Lighting); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, image); GL.Begin(BeginMode.Quads); GL.TexCoord2(0, 0); GL.Vertex3(0, 0, 0); GL.TexCoord2(0, h); GL.Vertex3(w, 0, 0); GL.TexCoord2(w, 0); GL.Vertex3(w, h, 0); GL.TexCoord2(w, h); GL.Vertex3(0, h, 0); GL.End(); GL.Disable(EnableCap.Texture2D); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Modelview); } private void Render() { if (!this.GLContextLoaded) { return; } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); this.DrawImage(this.currentTextureId); glControl1.SwapBuffers(); } private Bitmap currentBitmap = null; private void OnPaintGL(object sender, PaintEventArgs e) { currentBitmap = DaltonEyes.Properties.Resources.testImage; if (currentBitmap != null) { this.currentTextureId = this.LoadTexture(currentBitmap); } this.Render(); } |
idontknow
unregistriert
C#-Quelltext |
|
1 2 3 4 5 6 7 8 |
float[] vertexVertices = { -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f }; float[] textureVertices = { 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; int handleAPosition = GL.GetAttribLocation(program, "a_position"); int handleATexcoord = GL.GetAttribLocation(program, "a_texcoord"); GL.EnableVertexAttribArray(handleAPosition); GL.EnableVertexAttribArray(handleATexcoord); GL.VertexAttribPointer(handleAPosition, 2, VertexAttribPointerType.Float, false, 0, vertexVertices); GL.VertexAttribPointer(handleATexcoord, 2, VertexAttribPointerType.Float, false, 0, textureVertices); |
Alter Hase
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
varying vec2 texCoord; void main() { texCoord = gl_MultiTexCoord0.st; vec4 pos = gl_ModelViewMatrix * gl_Vertex; gl_Position = gl_ProjectionMatrix * pos; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
varying vec2 texCoord; void main() { texCoord = gl_MultiTexCoord0.st; vec4 pos = gl_ModelViewMatrix * gl_Vertex; gl_Position = gl_ProjectionMatrix * pos; } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
private void OnLoadGL(object sender, EventArgs e) { this.GLContextLoaded = true; this.CreateShaders( DaltonEyes.Properties.Resources.testVertexShader, DaltonEyes.Properties.Resources.testFragmentShader, out vertexShaderObject, out fragmentShaderObject, out shaderProgram); this.SetupViewport(); this.InitTexturing(); } public void DrawImage(int image) { int w = glControl.Width; int h = glControl.Height; GL.Disable(EnableCap.Lighting); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, image); GL.Begin(BeginMode.Quads); GL.TexCoord2(0, 1); GL.Vertex3(0, 0, 0); GL.TexCoord2(1, 1); GL.Vertex3(w, 0, 0); GL.TexCoord2(1, 0); GL.Vertex3(w, h, 0); GL.TexCoord2(0, 0); GL.Vertex3(0, h, 0); GL.End(); GL.Disable(EnableCap.Texture2D); GL.PopMatrix(); } private bool awaitingFrame = true; private void OnPaintGL(object sender, PaintEventArgs e) { if (this.currentBitmap != null) { Bitmap bmp = (Bitmap)this.currentBitmap; this.awaitingFrame = true; this.currentTextureId = this.LoadTexture(bmp); this.Render(); bmp.Dispose(); GL.DeleteTexture(this.currentTextureId); } } private void OnNewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs) { if (this.awaitingFrame) { this.awaitingFrame = false; this.currentBitmap = (Bitmap)eventArgs.Frame.Clone(); this.FPSUpdateFrame(true); this.glControl.Invalidate(); } else { this.FPSUpdateFrame(false); } } |
Wieso ist mein code denn veraltet bzw. was genau muss ich tun, damit er es nichtmehr ist?
Werbeanzeige