Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Text;
- using System.Threading.Tasks;
- using OpenTK;
- namespace OpenGLTutorial1
- {
- public class Program
- {
- static void Main ()
- {
- Game window = new Game (640, 480);
- window.Run ();
- }
- }
- }
- using System;
- using OpenTK;
- using OpenTK.Graphics;
- using OpenTK.Graphics.OpenGL;
- using System.Drawing;
- using OpenTK.Input;
- namespace OpenGLTutorial1
- {
- public class Game : GameWindow
- {
- int texture;
- public Game(int width, int height): base (width, height)
- {
- GL.Enable (EnableCap.Texture2D);
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad (e);
- texture = ContentPipe.LoadTexture("tiles.png");
- }
- protected override void OnUpdateFrame(FrameEventArgs e)
- {
- base.OnUpdateFrame (e);
- }
- protected override void OnRenderFrame(FrameEventArgs e)
- {
- base.OnRenderFrame (e);
- GL.Clear (ClearBufferMask.ColorBufferBit);
- GL.ClearColor (Color.CornflowerBlue);
- GL.BindTexture (TextureTarget.Texture2D, texture);
- GL.Begin (PrimitiveType.Quads);
- GL.Color3 (Color.Red);
- GL.TexCoord2 (0, 0);
- GL.Vertex2 (0, 0);
- GL.Color3 (Color.Blue);
- GL.TexCoord2 (1, 0);
- GL.Vertex2 (1, 0);
- GL.Color3 (Color.Green);
- GL.TexCoord2 (1, -1);
- GL.Vertex2 (1, -1);
- GL.Color3 (Color.Orange);
- GL.TexCoord2 (0, -1);
- GL.Vertex2 (0, -1);
- GL.End ();
- this.SwapBuffers ();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using OpenTK;
- using OpenTK.Graphics.OpenGL;
- using System.Drawing;
- using System.Drawing.Imaging;
- namespace OpenGLTutorial1
- {
- public class ContentPipe
- {
- public static int LoadTexture (string path)
- {
- if(!File.Exists ("Content/" + path))
- {
- throw new FileNotFoundException("File not found at Content/" + path + ".");
- }
- int id = GL.GenTexture ();
- GL.BindTexture (TextureTarget.Texture2D, id);
- Bitmap bmp = new Bitmap ("Content/" + path);
- BitmapData data = bmp.LockBits
- (
- new Rectangle (0, 0, bmp.Width, bmp.Height),
- System.Drawing.Imaging.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.UnsignedInt, data.Scan0
- );
- bmp.UnlockBits (data);
- GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)
- TextureWrapMode.Clamp);
- GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)
- TextureWrapMode.Clamp);
- GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)
- TextureMinFilter.Linear);
- GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)
- TextureMagFilter.Linear);
- return id;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement