/* * creating the window for the 3d opengl graphics engine * * */ public static void displayWindow() { Glut.glutInit(); /* * Glut.GLUT_DOUBLE: Double buffer removes any tearing/flickering of the screen- * -Drawing on the back buffer (video memory) * Glut.GLUT_DEPTH: Location and color of the screen. Closest gets drawn. * */ Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); // width and height of the engine's window Glut.glutCreateWindow("3D OpenGL Graphics Engine"); // title of the engine Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(closeProgram); Gl.Enable(EnableCap.DepthTest); SquareDrawing(); Glut.glutMainLoop(); }
static void Main(string[] args) { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); // compile the shader program program = new ShaderProgram(VertexShader, FragmentShader); // set the view and projection matrix, which are static throughout this tutorial program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); // create a triangle triangle = new VBO <Vector3>(new Vector3[] { new Vector3(0, 1, 0), new Vector3(-1, -1, 0), new Vector3(1, -1, 0) }); triangleElements = new VBO <uint>(new uint[] { 0, 1, 2 }, BufferTarget.ElementArrayBuffer); // create a square square = new VBO <Vector3>(new Vector3[] { new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0), new Vector3(-1, -1, 0) }); squareElements = new VBO <uint>(new uint[] { 0, 1, 2, 3 }, BufferTarget.ElementArrayBuffer); Glut.glutMainLoop(); }
static void Main(string[] args) { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(OnKeyboard); time_ = 0; Matrix4 modelMatrix = CreateModelMatrix(time_); context_ = new NeutrinoGl.Context("..\\..\\effects\\textures\\"); effectModel_ = new NeutrinoGl.EffectModel(context_, new Neutrino.Effect_params_test()); effect_ = new NeutrinoGl.Effect(effectModel_, Neutrino._math.vec3_(modelMatrix[3].x, modelMatrix[3].y, modelMatrix[3].z), null); effect_.neutrinoEffect().setEmitterPropertyValue(null, "Color", Neutrino._math.vec3_(1, 1, 0)); // load a crate texture watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
/*private void keyboard(byte key, int x, int y) * { * int mod = Glut.glutGetModifiers(); * if(mod==Glut.GLUT_ACTIVE_CTRL) ctrl=true; * else ctrl=false; * }*/ /** * luo glut ikkuna, aseta callbackit ja luo tyhjä texture */ void create(int width, int height) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB); Glut.glutInitWindowSize(width, height); Glut.glutInitWindowPosition(100, 100); Glut.glutCreateWindow("CSPaint"); Glut.glutDisplayFunc(new Glut.DisplayCallback(display)); Glut.glutMouseFunc(new Glut.MouseCallback(mouseButton)); Glut.glutMotionFunc(new Glut.MotionCallback(mouseMotion)); Glut.glutCloseFunc(new Glut.CloseCallback(closeWindow)); Glut.glutReshapeFunc(new Glut.ReshapeCallback(reshape)); //Glut.glutKeyboardFunc(new Glut.KeyboardCallback(keyboard)); Gl.glDisable(Gl.GL_LIGHTING); Gl.glClearColor(1, 1, 1, 1); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); Gl.glDisable(Gl.GL_CULL_FACE); Gl.glDisable(Gl.GL_DEPTH_TEST); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0, width, height, 0, -1, 1); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); // luo yksi taso newLayer(); }
/** * loppulätinät */ public void shutdown() { running = false; Glut.glutMouseFunc(null); Glut.glutMotionFunc(null); Glut.glutCloseFunc(null); Glut.glutReshapeFunc(null); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // enable blending and set to accumulate the star colors Gl.Disable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, new Vector3(0, 1, 0))); // load the star texture starTexture = new Texture("star.bmp"); // each star is simply a quad star = new VBO <Vector3>(new Vector3[] { new Vector3(-1, -1, 0), new Vector3(1, -1, 0), new Vector3(1, 1, 0), new Vector3(-1, 1, 0) }); starUV = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); starQuads = new VBO <int>(new int[] { 0, 1, 2, 0, 2, 3 }, BufferTarget.ElementArrayBuffer); // create 50 stars for this tutorial int numStars = 50; for (int i = 0; i < numStars; i++) { stars.Add(new Star(0, (float)i / numStars * 4f, new Vector3((float)generator.NextDouble(), (float)generator.NextDouble(), (float)generator.NextDouble()))); } font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 10"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); Gl.Enable(EnableCap.DepthTest); program = new ShaderProgram(VertexShader, FragmentShader); program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); program["light_direction"].SetValue(new Vector3(0, 0, 1)); program["enable_lighting"].SetValue(lighting); crateTexture = new Texture("crate.jpg"); cube = new VBO<Vector3>(new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), // top new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), // bottom new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), // front face new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), // back face new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), // left new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }); // right cubeNormals = new VBO<Vector3>(new Vector3[] { new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0) }); cubeUV = new VBO<Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); cubeQuads = new VBO<int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main() { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Toutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Gl.Enable(EnableCap.DepthTest); ShaderProgram = new ShaderProgram(VertexShader, FragmentShader); ShaderProgram.Use(); ShaderProgram["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); ShaderProgram["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up)); CrateTexture = new Texture("Grass1.jpg"); cube = new VBO <Vector3>(new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }); int x1 = 500; int y1 = -5; int z1 = 10; int x2 = -500; int y2 = -50; int z2 = -1000; cube = new VBO <Vector3>(new Vector3[] { new Vector3(x1, y1, z2), new Vector3(x2, y1, z2), new Vector3(x2, y1, z1), new Vector3(x1, y1, z1), //top new Vector3(x1, y2, z1), new Vector3(x2, y2, z1), new Vector3(x2, y2, z2), new Vector3(x1, y2, z2), //bottom new Vector3(x1, y1, z1), new Vector3(x2, y1, z1), new Vector3(x2, y2, z1), new Vector3(x1, y2, z1), //front face new Vector3(x1, y2, z2), new Vector3(x2, y2, z2), new Vector3(x2, y1, z2), new Vector3(x1, y1, z2), //back face new Vector3(x2, y1, z1), new Vector3(x2, y1, z2), new Vector3(x2, y2, z2), new Vector3(x2, y2, z1), //left face new Vector3(x1, y1, z2), new Vector3(x1, y1, z1), new Vector3(x1, y2, z1), new Vector3(x1, y2, z2) }); //right face cubeUV = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); cubeQuads = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(OpenGL.EnableCap.DepthTest); // compile the shader program program = new ShaderProgram(VertexShader, FragmentShader); // set the view and projection matrix, which are static throughout this tutorial program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); // load a crate texture crateTexture = new Texture("res/textures/willem_side.png"); // create a crate with vertices and UV coordinates cube[0] = new VBO <Vector3>(new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }); cubeUV[0] = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); //crateTexture = new Texture("res/textures/crate.jpg"); cubeQuads = new VBO <uint>(new uint[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_ALPHA | Glut.GLUT_STENCIL | Glut.GLUT_MULTISAMPLE); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Gl.Enable(EnableCap.DepthTest); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // add our mouse callbacks for this tutorial Glut.glutMouseFunc(OnMouse); Glut.glutMotionFunc(OnMove); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // create our camera camera = new Camera(new Vector3(0, 0, 50), Quaternion.Identity); camera.SetDirection(new Vector3(0, 0, -1)); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["model_matrix"].SetValue(Matrix4.Identity); objectFile = new ObjLoader("enterprise/enterprise.obj", program); // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 16"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
public static void Main() { Console.WriteLine(Math.Cos(DegRad(90))); Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(DefaultWidth, DefaultHeight); Glut.glutCreateWindow("OpenGL Toutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutReshapeFunc(OnReshape); Floor.DefObject(); Object_List.Add(Floor); Box.DefObject(); Object_List.Add(Box); Gl.Enable(EnableCap.DepthTest); Shader_Program = new ShaderProgram(VertexShader, FragmentShader); Shader_Program.Use(); Shader_Program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)CurrentHeight / CurrentHeight, 0.1f, 1000f)); Shader_Program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up)); Texture1 = new Texture("Grass1.jpg"); Texture2 = new Texture("Grass2.jpg"); /*Cube = new VBO<Vector3>(new Vector3[] { * new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), //top * new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), //bottom * new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), //front face * new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), //back face * new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), //left face * new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }); //right face * CubeUV = new VBO<Vector2>(new Vector2[] { * new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), * new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), * new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), * new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), * new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), * new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); * CubeQuads = new VBO<int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer);*/ watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
private static void InitializeGlut() { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(ConfigurationHandler.WindowWidth, ConfigurationHandler.WindowHeight); Glut.glutCreateWindow("Tetris"); Glut.glutFullScreen(); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(KeyboardManager.OnKeyboardDown); Glut.glutSpecialFunc(KeyboardManager.OnSpecialKeyboardDown); Glut.glutSpecialUpFunc(KeyboardManager.OnSpecialKeyboardUp); }
public void Init() { //Open GL init #region Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("Maraca craft"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(OnKeyboardDown); Gl.ClearColor(0, 0, 0, 1); //Alpha enabled Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); #endregion //Load shader program = new ShaderProgram(VertexShader, FragmentShader); //Create perspective program.Use(); program["projection_matrix"].SetValue( Matrix4.CreatePerspectiveFieldOfView(0.95f, (float)width / height, 0.1f, 1000f)); Vector3 camPos = new Vector3(0, 0, 0); //-5 3 -5 program["view_matrix"].SetValue( Matrix4.CreateTranslation(new Vector3(0, 0, 0)) * Matrix4.LookAt(new Vector3(0, 0, -1), camPos, new Vector3(0, 1, 0))); player = new Player(0, 0, 0); CreateModels(); Glut.glutMainLoop(); }
static void Main() { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL UI: Example 1"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(() => { }); // only here for mac os x Glut.glutCloseFunc(OnClose); Glut.glutMouseFunc(OnMouseClick); Glut.glutMotionFunc(OnMouseMove); Glut.glutPassiveMotionFunc(OnMouseMove); Glut.glutReshapeFunc(OnResize); Glut.glutKeyboardFunc(OnKeyboard); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(width, height); // create some centered text OpenGL.UI.Text welcome = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Welcome to OpenGL", OpenGL.UI.BMFont.Justification.Center); welcome.RelativeTo = OpenGL.UI.Corner.Center; // create some colored text OpenGL.UI.Text coloredText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "using C#", OpenGL.UI.BMFont.Justification.Center); coloredText.Position = new Point(0, -30); coloredText.Color = new Vector3(0.2f, 0.3f, 1f); coloredText.RelativeTo = OpenGL.UI.Corner.Center; // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(welcome); OpenGL.UI.UserInterface.AddElement(coloredText); // enter the glut main loop (this is where the drawing happens) Glut.glutMainLoop(); }
public static void Build() { for (int i = 0; i < _keysArrayUp.Length; i++) { _keysArrayUp[i] = true; } Glut.glutDisplayFunc(OnDisplay); Glut.glutReshapeFunc(OnReshape); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(OnKeyboard); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutTimerFunc(100, RenderTimer, 0); }
static void Main(string[] args) { wplayer.URL = "song.mp3"; wplayer.controls.stop(); Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("UAS IF3260 - Grafika Komputer"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutMouseWheelFunc(MouseWheel); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Multisample); Gl.Enable(EnableCap.ProgramPointSize); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); program = new ShaderProgram(VertexShader, FragmentShader); program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 6), new Vector3(1.2f, 0.2f, 0f), new Vector3(0, 1, 0))); program["light_direction"].SetValue(new Vector3(0, 0, 1)); program["enable_lighting"].SetValue(lighting); carmodel = new CarModel(); rain = new Rain(); smoke = new Smoke(); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
public static void Main() { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(DefaultWidth, DefaultHeight); Glut.glutCreateWindow("OpenGL Toutorial"); Camera camera = new Camera(); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutReshapeFunc(camera.OnReshape); Gl.Enable(EnableCap.DepthTest); Texture1 = new Texture("Grass1.jpg"); Cube = new VBO <Vector3>(new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), //top new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), //bottom new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), //front face new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), //back face new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), //left face new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }); //right face CubeUV = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); CubeQuads = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer); Glut.glutMainLoop(); }
static void Main(string[] args) { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); // compile the shader program program = new ShaderProgram(VertexShader, FragmentShader); // set the view and projection matrix, which are static throughout this tutorial program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); // create a triangle with vertices and colors triangle = new VBO <Vector3>(new Vector3[] { new Vector3(0, 1, 0), new Vector3(-1, -1, 0), new Vector3(1, -1, 0) }); triangleColor = new VBO <Vector3>(new Vector3[] { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }); triangleElements = new VBO <int>(new int[] { 0, 1, 2 }, BufferTarget.ElementArrayBuffer); // create a square with vertices an colors square = new VBO <Vector3>(new Vector3[] { new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0), new Vector3(-1, -1, 0) }); squareElements = new VBO <int>(new int[] { 0, 1, 2, 3 }, BufferTarget.ElementArrayBuffer); squareColor = new VBO <Vector3>(new Vector3[] { new Vector3(0.5f, 0.5f, 1), new Vector3(0.5f, 0.5f, 1), new Vector3(0.5f, 0.5f, 1), new Vector3(0.5f, 0.5f, 1) }); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // enable blending and set to accumulate the star colors Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, new Vector3(0, 1, 0))); program["model_matrix"].SetValue(Matrix4.Identity); // load the flag texture flagTexture = new Texture("flag.png"); // create the flag, which is just a plane with a certain number of segments List <Vector3> vertices = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <uint> triangles = new List <uint>(); for (int x = 0; x < 40; x++) { for (int y = 0; y < 40; y++) { vertices.Add(new Vector3((x - 20) / 5.0f, (y - 20) / 10.0f, 0)); uvs.Add(new Vector2(x / 39.0f, 1 - y / 39.0f)); if (y == 39 || x == 39) { continue; } triangles.Add((uint)(x * 40 + y)); triangles.Add((uint)((x + 1) * 40 + y)); triangles.Add((uint)((x + 1) * 40 + y + 1)); triangles.Add((uint)(x * 40 + y)); triangles.Add((uint)((x + 1) * 40 + y + 1)); triangles.Add((uint)(x * 40 + y + 1)); } } flagVertices = new VBO <Vector3>(vertices.ToArray()); flagUVs = new VBO <Vector2>(uvs.ToArray()); flagTriangles = new VBO <uint>(triangles.ToArray(), BufferTarget.ElementArrayBuffer); // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 11"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE); // multisampling makes things beautiful! Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Multisample); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up)); program["light_direction"].SetValue(new Vector3(0, 0, 1)); program["enable_lighting"].SetValue(lighting); program["normalTexture"].SetValue(1); program["enable_mapping"].SetValue(normalMapping); brickDiffuse = new Texture("AlternatingBrick-ColorMap.png"); brickNormals = new Texture("AlternatingBrick-NormalMap.png"); Vector3[] vertices = new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), // top new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), // bottom new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), // front face new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), // back face new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), // left new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }; cube = new VBO <Vector3>(vertices); Vector2[] uvs = new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }; cubeUV = new VBO <Vector2>(uvs); List <int> triangles = new List <int>(); for (int i = 0; i < 6; i++) { triangles.Add(i * 4); triangles.Add(i * 4 + 1); triangles.Add(i * 4 + 2); triangles.Add(i * 4); triangles.Add(i * 4 + 2); triangles.Add(i * 4 + 3); } cubeTriangles = new VBO <int>(triangles.ToArray(), BufferTarget.ElementArrayBuffer); Vector3[] normals = Geometry.CalculateNormals(vertices, triangles.ToArray()); cubeNormals = new VBO <Vector3>(normals); Vector3[] tangents = CalculateTangents(vertices, normals, triangles.ToArray(), uvs); cubeTangents = new VBO <Vector3>(tangents); // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 13"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); //двойная буфферизация и буфер глубины //двойная буфферизация позволяет избежать проблем с отрисовкой(юзер видит как оно рисуется) //Сначала рисуется на "Заднем" кадре, а потом меняет местами кадры //буфер глубины хранит не только инфу о цветах, но и на какой глубине они находятся на экране(избегает overdrawing) Ближайший объект будет отрисован, а на заднем фоне удален Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutMouseFunc(OnMouseMove); Glut.glutReshapeFunc(OnReshape); Glut.glutCloseFunc(OnClose); //тестим порядок Z координаты фрагментов. Без нее будет пздц //Depth тест не рисует все что на "заднем плане" Gl.Disable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); program = new ShaderProgram(VertexShader, FragmentShader); program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView( 0.45f, (float)width / height, //условия когда объект больше не рендерится(ближе 0.1, дальше 1000) 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt( new Vector3(0, 0, 10), //в 10 юнитах от источника Vector3.Zero, //смотри на источниk Vector3.Up)); //направление вверх? program["light_direction"].SetValue(new Vector3(0, 0, 1)); program["enable_lighting"].SetValue(lightning); //загрузка текстуры texture = new Texture("glass.bmp"); //куб cube = new VBO <Vector3>(new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), //верх new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), //низ new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), //фронт new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), //тыл new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), //лево new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }); //право cubeUV = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); cubeNormals = new VBO <Vector3>(new Vector3[] { new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), //указывает прямо вверх new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), //указывает вниз new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), //указывает вперед new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), //указывает назад new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), //указывает влево new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0) //указывает вправо }); cubeElements = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer); Console.WriteLine("Я консоль для проверки корректности введенных вами данных"); //начало таймера watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { //Open GL init #region Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("Tu mama es maraca"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Gl.ClearColor(0, 0, 0, 1); //Alpha enabled Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); #endregion //Load shader program = new ShaderProgram(VertexShader, FragmentShader); //Create perspective program.Use(); program["projection_matrix"].SetValue( Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue( Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); //random texture for each if (numShapes > maxX * maxY) { numShapes = maxX * maxY; } texRandom = new int[numShapes]; crateTexture = new Texture("crate.jpg"); rectTexture = new Texture("4922.jpg"); pyTexture = new Texture("tile.jpg"); Random r = new Random(); for (int i = 0; i < numShapes; i++) { texRandom[i] = r.Next(3); } //Cube vertices and uv #region cube = new VBO <Vector3>( new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1), } ); cubeElements = new VBO <int>( new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer ); cubeUV = new VBO <Vector2>( new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) } ); #endregion Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE); // multisampling makes things beautiful! Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // enable blending and set to accumulate the star colors Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.ProgramPointSize); Gl.Enable(EnableCap.Multisample); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, new Vector3(0, 1, 0))); program["model_matrix"].SetValue(Matrix4.Identity); program["static_colors"].SetValue(false); // load the particle texture particleTexture = new Texture("star.bmp"); // set up the particlePoints VBO, which will stay constant uint[] points = new uint[particleCount]; for (uint i = 0; i < points.Length; i++) { points[i] = i; } particlePoints = new VBO <uint>(points, BufferTarget.ElementArrayBuffer); // set up the particleColors, which we'll just keep static Vector3[] colors = new Vector3[particleCount]; for (int i = 0; i < colors.Length; i++) { colors[i] = new Vector3((float)generator.NextDouble(), (float)generator.NextDouble(), (float)generator.NextDouble()); } particleColors = new VBO <Vector3>(colors); // build up our first batch of 1000 particles and 1000 static colors for (int i = 0; i < particleCount; i++) { particles.Add(new Particle(Vector3.Zero, 0)); } // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 12"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { System.Diagnostics.Debug.Print("{0}", a.DothisVertexThing1(1)); //Open an opengl window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Testing"); //provide the Glut callbacks that are necessary fro running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutReshapeFunc(OnReshape); // enable depth otesting to ensure correct z-ordering Gl.Disable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //Compile the shader program program = new ShaderProgram(VertexShader, FragmentShader); //set the view and projection matrix, which are static throughout this tutorial program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.UnitY)); program["light_direction"].SetValue(new Vector3(0, 0, 1)); program["enable_lighting"].SetValue(lighting); //load our crate texture glassTexture = new Texture("glass.bmp"); //create cube with vertices and colors cube = new VBO <Vector3>(new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), //top new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), //bottom new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), // front new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), //back new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), //left new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) //right }); cubeUV = new VBO <Vector2>(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }); cubeNormals = new VBO <Vector3>(new Vector3[] { new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, -1, 0), new Vector3(0, 1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0) }); cubeElements = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { //Open GL init #region Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("Tu mama es maraca"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Gl.ClearColor(0, 0, 0, 1); //Alpha enabled Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); #endregion //Load shader program = new ShaderProgram(VertexShader, FragmentShader); //Create perspective program.Use(); program["projection_matrix"].SetValue( Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue( Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); float anglePerFace = (float)360 / FACES; Console.WriteLine("ANGLE PER FACE: " + anglePerFace); Vector3[] v = new Vector3[FACES * 3]; Vector3 prevVert = new Vector3(RADIUS, 0, 0); for (int i = 0, currentFace = 1; i < FACES * 3; i += 3, currentFace++) { float angle = currentFace * anglePerFace; float x = (float)Math.Cos(angle * (Math.PI / 180)) * RADIUS; float y = (float)Math.Sin(angle * (Math.PI / 180)) * RADIUS; v[i] = new Vector3(0, 0, 0); v[i + 1] = prevVert; v[i + 2] = new Vector3(x, y, 0); prevVert = v[i + 2]; Console.WriteLine(angle); Console.WriteLine("Current Face: " + currentFace); Console.WriteLine("VERTEX: " + i + " X: " + v[i].X + " Y: " + v[i].Y); Console.WriteLine("VERTEX: " + (i + 1) + " X: " + v[i + 1].X + " Y: " + v[i + 1].Y); Console.WriteLine("VERTEX: " + (i + 2) + " X: " + v[i + 2].X + " Y: " + v[i + 2].Y); Console.WriteLine("---------------"); } #region crateTexture = new Texture("crate.jpg"); cube = new VBO <Vector3>(v); int[] ce = new int[FACES * 3]; for (int i = 0; i < FACES * 3; i++) { ce[i] = i; Console.Write(i + " "); } cubeElements = new VBO <int>( ce, BufferTarget.ElementArrayBuffer ); Vector2[] uv = new Vector2[FACES * 4]; for (int i = 0; i < FACES * 4; i += 4) { uv[i] = new Vector2(0, 0); uv[i + 1] = new Vector2(1, 0); uv[i + 2] = new Vector2(1, 1); uv[i + 3] = new Vector2(0, 1); } cubeUV = new VBO <Vector2>(uv); #endregion watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
private void StartOpenGl() { exit = false; Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_ALPHA | Glut.GLUT_STENCIL | Glut.GLUT_MULTISAMPLE); // http://www.lighthouse3d.com/cg-topics/glut-and-freeglut/ // Note: glutSetOption is only available with freeglut Glut.glutSetOption(Glut.GLUT_ACTION_ON_WINDOW_CLOSE, Glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Test"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutSpecialFunc(OnSpecialKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutSpecialUpFunc(OnSpecialKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // add our mouse callbacks for this tutorial Glut.glutMouseFunc(OnMouse); Glut.glutMotionFunc(OnMove); #region GL_VERSION //this will return your version of opengl int major, minor; major = Gl.GetInteger(GetPName.MajorVersion); minor = Gl.GetInteger(GetPName.MinorVersion); GameCore.TheGameCore.RaiseMessage("Major " + major + " Minor " + minor); // Console.WriteLine("Major " + major + " Minor " + minor); //you can also get your GLSL version, although not sure if it varies from the above GameCore.TheGameCore.RaiseMessage("GLSL " + Gl.GetString(StringName.ShadingLanguageVersion)); #endregion Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); RenderObjects.RenderObjects.TheResourceManager = theResourceManager; Camera camera = new Camera(new Vector3(0, 20, 10), Quaternion.Identity); camera.SetDirection(new Vector3(1, -3, -1)); TheGameStatus.TheEnvironment = new Environment(); TheGameStatus.TheCamera = camera; theSceneManager = new SceneManager(TheGameStatus, TheUserInputPlayer, theKeyBindings, theResourceManager, new RenderStatus() { Width = width, Height = height }); theSceneManager.AddCamera(camera); theSceneManager.AddLayer(new RenderLayerSkyBox()); theSceneManager.AddLayer(new RenderLayerGame()); theSceneManager.AddLayer(new RenderLayerMapDrawArrays()); theSceneManager.AddLayer(new RenderLayerHud()); theSceneManager.AddLayer(layerInfo = new RenderLayerTextInfo()); theSceneManager.OnLoad(); watch = Stopwatch.StartNew(); Glut.glutMainLoop(); GameCore.TheGameCore.OnGameEventHandler(new GameEventArgs(GameEventArgs.Types.RendererExited)); }
static void Main(string[] args) { while (true) { try { Console.WriteLine("Input the number of levels to recurse. Must be greater than or equal to zero.\r\n" + "Mouse to look and WASD to move. Hold R to run. F to toggle fullscreen.\r\n" + "O to toggle between walking and flying. When flying, use E/Q to ascend/descend."); if ((levelNum = Convert.ToInt32(Console.ReadLine())) >= 0) { break; } } catch { Console.WriteLine("Please input an integer greater than or equal to zero."); } } // init GLUT and create window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE); // multisampling purportedly "makes things beautiful!" Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("Fractal"); // register main loop callbacks Glut.glutDisplayFunc(renderScene); Glut.glutIdleFunc(idle); Glut.glutCloseFunc(onClose); //register resize callback Glut.glutReshapeFunc(OnReshape); // register keyboard callbacks Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); // register mouse callbacks Glut.glutMotionFunc(OnMove); Glut.glutPassiveMotionFunc(OnMove); //hide mouse Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE); //enable depth testing Gl.Enable(EnableCap.DepthTest); //enable alpha blending Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //compile shader program = new ShaderProgram(VertexShader, FragmentShader); //make a camera camera = new Camera(new Vector3(0, 0, 0), Quaternion.Identity); //set the camera starting location here camera.SetDirection(new Vector3(0, 0, -1)); // set the view and projection matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.90f, (float)width / height, 0.01f, 1000f)); program["light_direction"].SetValue(new Vector3(-0.3f, -0.8f, -0.7f)); //pink program["light2_direction"].SetValue(new Vector3(0.7f, -0.8f, 0.3f)); //cyan program["light3_direction"].SetValue(new Vector3(0.3f, -0.8f, 0.7f)); //celadon program["light4_direction"].SetValue(new Vector3(-0.7f, -0.8f, -0.3f)); //yellow program["enable_lighting"].SetValue(lighting); //set background color Gl.ClearColor(0.99f, 0.93f, 0.85f, 1f); // load each block's model and decomposition rule from files and add to blockRef int fCount = Directory.GetFiles("assets", "*", SearchOption.TopDirectoryOnly).Length; for (int n = 0; n < fCount / 2; ++n) { List <Vector3> indexVertices = new List <Vector3>(); List <Vector3> indexNormals = new List <Vector3>(); List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <Vector3> edgeVertices = new List <Vector3>(); StreamReader sr = new StreamReader("assets/" + n.ToString() + ".txt"); while (!sr.EndOfStream) { string[] fields = sr.ReadLine().Split(); if (fields[0] == "v") //a vertex { Vector3 vertex = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3])); indexVertices.Add(vertex); } else if (fields[0] == "vn") //a vertex normal { Vector3 normal = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3])); indexNormals.Add(normal); } else if (fields[0] == "f") //a face { for (int i = 1; i < fields.Length; ++i) { string[] indices = fields[i].Split('/'); vertices.Add(indexVertices[Convert.ToInt32(indices[0]) - 1]); normals.Add(indexNormals[Convert.ToInt32(indices[2]) - 1]); } } else if (fields[0] == "l") //an edge { edgeVertices.Add(indexVertices[Convert.ToInt32(fields[1]) - 1]); edgeVertices.Add(indexVertices[Convert.ToInt32(fields[2]) - 1]); } } sr.Close(); //create the block object Block newBlock = new Block(); newBlock.position = new Vector3(0, 0, 0); newBlock.yOrientation = 0; newBlock.scale = new Vector3(1, 1, 1); newBlock.ID = n; //fill the block object with data loaded from .obj above newBlock.verticeData = vertices.ToArray(); newBlock.normalData = normals.ToArray(); newBlock.edgeVerticeData = edgeVertices.ToArray(); blockRef.Add(newBlock); //load the decomposition rule for this block List <DecompBlock> newDRule = new List <DecompBlock>(); float scaleConst = 1; float unitConst = 1; sr = new StreamReader("assets/" + n.ToString() + "rule.txt"); while (!sr.EndOfStream) { string[] fields = sr.ReadLine().Split(); if (fields[0] != "#") //check its not a comment { if (fields[0] == "!") { //setting scale down values. e.g. if set to 1/3 and 2/3, each new block would be scaled down //by 1/3, and each 1 unit offset written in the rule file would be scaled to move the block 2/3 units instead. //default 1 and 1: no scaling applied. scaleConst = Convert.ToSingle(fields[1]); unitConst = Convert.ToSingle(fields[2]); } else { //load in fields DecompBlock newDBlock = new DecompBlock(); newDBlock.ID = Convert.ToInt32(fields[0]); newDBlock.posOffset = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3])); newDBlock.xAngleOffset = Convert.ToSingle(fields[4]); newDBlock.extraScale = new Vector3(1, 1, 1); newDBlock.unitScaleConst = unitConst; newDBlock.scaleDownConst = scaleConst; if (fields.Length > 5) { newDBlock.extraScale = new Vector3(Convert.ToInt32(fields[5]), Convert.ToInt32(fields[6]), Convert.ToInt32(fields[7])); } //add block to rule newDRule.Add(newDBlock); } } } sr.Close(); decompRules.Add(newDRule); } Block seedBlock = blockRef[0]; blocks = Decompose(seedBlock, levelNum); //merge all vertices and normals into a an interleaved vbo List <Vector3> preVertices = new List <Vector3>(); List <Vector3> preNormals = new List <Vector3>(); List <Vector3> preEdges = new List <Vector3>(); foreach (Block block in blocks) { foreach (Vector3 point in block.verticeData) { Vector4 preVertex = (new Vector4(point, 1) * Matrix4.CreateScaling(block.scale) * Matrix4.CreateRotationY(block.yOrientation) + new Vector4(block.position, 1)); preVertices.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2))); } foreach (Vector3 normal in block.normalData) { Vector4 preNormal = (new Vector4(normal, 1) * Matrix4.CreateScaling(new Vector3(Math.Sign(block.scale[0]), Math.Sign(block.scale[1]), Math.Sign(block.scale[2]))) * Matrix4.CreateRotationY(block.yOrientation)); preNormals.Add(new Vector3(Convert.ToSingle(Math.Round(preNormal.Get(0))), Convert.ToSingle(Math.Round(preNormal.Get(1))), Convert.ToSingle(Math.Round(preNormal.Get(2))))); } foreach (Vector3 point in block.edgeVerticeData) { Vector4 preVertex = (new Vector4(point, 1) * Matrix4.CreateScaling(block.scale) * Matrix4.CreateRotationY(block.yOrientation) + new Vector4(block.position, 1)); preEdges.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2))); } } //exportOBJ(preVertices, preNormals); //exports fractal if left uncommented drawVertices = new VBO <Vector3>(preVertices.ToArray()); drawNormals = new VBO <Vector3>(preNormals.ToArray()); drawEdges = new VBO <Vector3>(preEdges.ToArray()); List <uint> drawOrder = new List <uint>(); for (int x = 0; x < preVertices.Count; ++x) { drawOrder.Add(Convert.ToUInt32(x)); } drawElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer); drawOrder.Clear(); for (int x = 0; x < preEdges.Count; ++x) { drawOrder.Add(Convert.ToUInt32(x)); } drawEdgeElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer); watch = System.Diagnostics.Stopwatch.StartNew(); // enter GLUT event processing cycle Glut.glutMainLoop(); }
static void Main(string[] args) { //Open GL init #region Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("Tu mama es maraca"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutCloseFunc(OnClose); Gl.ClearColor(0, 0, 0, 1); //Alpha enabled Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Blend); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); #endregion //Load shader program = new ShaderProgram(VertexShader, FragmentShader); //Create perspective program.Use(); program["projection_matrix"].SetValue( Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue( Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0))); //Cube vertices and uv #region crateTexture = new Texture("crate.jpg"); cube = new VBO <Vector3>( new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1), } ); cubeElements = new VBO <int>( new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer ); cubeUV = new VBO <Vector2>( new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) } ); #endregion //Rect vertices and uv #region rectTexture = new Texture("4922.jpg"); rect = new VBO <Vector3>( new Vector3[] { new Vector3(2, 1, -2), new Vector3(-2, 1, -2), new Vector3(-2, 1, 2), new Vector3(2, 1, 2), new Vector3(2, -0, 2), new Vector3(-2, -0, 2), new Vector3(-2, -1, -2), new Vector3(2, -1, -2), new Vector3(2, 1, 2), new Vector3(-2, 1, 2), new Vector3(-2, 0, 2), new Vector3(2, 0, 2), new Vector3(2, -1, -2), new Vector3(-2, -1, -2), new Vector3(-2, 1, -2), new Vector3(2, 1, -2), new Vector3(-2, 1, 2), new Vector3(-2, 1, -2), new Vector3(-2, -1, -2), new Vector3(-2, 0, 2), new Vector3(2, 1, -2), new Vector3(2, 1, 2), new Vector3(2, 0, 2), new Vector3(2, -1, -2), } ); rectElements = new VBO <int>( new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer ); rectUV = new VBO <Vector2>( new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) } ); #endregion //Pyramid vertices and uv #region pyTexture = new Texture("tile.jpg"); pyramid = new VBO <Vector3>( new Vector3[] { new Vector3(1, 0, 1), new Vector3(-1, 0, 1), new Vector3(0.5f, 1, -0.5f), new Vector3(1, 0, -1), new Vector3(-1, 0, -1), new Vector3(0.5f, 1, -0.5f), new Vector3(1, 0, 1), new Vector3(1, 0, -1), new Vector3(0.5f, 1, -0.5f), new Vector3(-1, 0, 1), new Vector3(-1, 0, -1), new Vector3(0.5f, 1, -0.5f), } ); pyramidElements = new VBO <int>( new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, BufferTarget.ElementArrayBuffer ); pyUV = new VBO <Vector2>( new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), } ); #endregion watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main() { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL UI: Example 2"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(() => { }); // only here for mac os x Glut.glutCloseFunc(OnClose); Glut.glutMouseFunc(OnMouseClick); Glut.glutMotionFunc(OnMouseMove); Glut.glutPassiveMotionFunc(OnMouseMove); Glut.glutReshapeFunc(OnResize); Glut.glutKeyboardFunc(OnKeyboard); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(width, height); // create some centered text OpenGL.UI.Text selectText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Select A Character", OpenGL.UI.BMFont.Justification.Center); selectText.Position = new Point(0, 50); selectText.RelativeTo = OpenGL.UI.Corner.Center; OpenGL.UI.Text characterName = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "", OpenGL.UI.BMFont.Justification.Center); characterName.RelativeTo = OpenGL.UI.Corner.Center; characterName.Position = new Point(0, -70); // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(selectText); OpenGL.UI.UserInterface.AddElement(characterName); // the license for these icons is located in the data folder string[] characters = new string[] { "boy.png", "man.png", "girl1.png", "girl2.png", "girl3.png" }; textures = new Texture[characters.Length]; int xoffset = -characters.Length * 80 / 2 + 40; for (int i = 0; i < characters.Length; i++) { string character = characters[i]; // load a texture that will be used by a button textures[i] = new Texture(string.Format("data/{0}", character)); // create buttons in a row, each of which uses a Texture (the Texture gives the initial size of the Button in pixels) OpenGL.UI.Button button = new OpenGL.UI.Button(textures[i]); button.Position = new Point(xoffset, 5); button.RelativeTo = OpenGL.UI.Corner.Center; // change the color of the button when entering/leaving/clicking with the mouse button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0, 1f, 0.2f, 1.0f); button.OnMouseLeave = (sender, e) => button.BackgroundColor = Vector4.Zero; button.OnMouseDown = (sender, e) => button.BackgroundColor = new Vector4(0, 0.6f, 1f, 1f); button.OnMouseUp = (sender, e) => button.BackgroundColor = (OpenGL.UI.UserInterface.Selection == button ? new Vector4(0, 1f, 0.2f, 1.0f) : Vector4.Zero); // update the text with the character name when the button is clicked button.OnMouseClick = (sender, e) => characterName.String = string.Format("You selected {0}!", character); OpenGL.UI.UserInterface.AddElement(button); xoffset += 80; } // enter the glut main loop (this is where the drawing happens) Glut.glutMainLoop(); }
static void Main(string[] args) { AboutApp aboutApp = new AboutApp("OpenGL App", "1.0.0", "-----------", "Sebastian Tomczak, Politechnika Lubelska ", opis); Application.Run(aboutApp); if (aboutApp.GetStateOfStartOknoObslugi() == true) { PobieranieSciezki pobieranieSciezki = new PobieranieSciezki(); Application.Run(pobieranieSciezki); objPath = pobieranieSciezki.GetObjPath(); lighting = pobieranieSciezki.wlaczenieSw; natezenieSwiatla = pobieranieSciezki.natezenieSw; kierunekSwiatlaX = pobieranieSciezki.kierunekSwX; kierunekSwiatlaY = pobieranieSciezki.kierunekSwY; kierunekSwiatlaZ = pobieranieSciezki.kierunekSwZ; startOpenGL = pobieranieSciezki.startOpenGL; } if (startOpenGL == true) { Glut.glutInit(); MakingWindow(width, height, name); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); //Funkcja obslugujaca nacisniecia przyciskow Glut.glutKeyboardUpFunc(OnKeyboardUp); //Funkcja obslugujaca nacisniecia przyciskow Glut.glutMouseFunc(OnMouse); //Funckja obslugujaca ruch mysza Glut.glutMotionFunc(OnMove); //Funckja obslugujaca ruch mysza Glut.glutCloseFunc(OnClose); //Funkcja obslugujaca zamykanie wszystkiego shaderProgram = new ShaderProgram(VertexShader, FragmentShader); //Tworzenie programu odpowiedzialnego za Shadery kamera = new Camera(new Vector3(0, 0, 10f), Quaternion.Identity); //Wykorzystanie klasy Camera i stworzenie jej kamera.SetDirection(new Vector3(0, 0, -1.25f)); //Ustawienie kierunku kamery. shaderProgram.Use(); //uruchomienie programu odpowiedzialnego za Shadery shaderProgram["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); //Stworzenie stożka widoku shaderProgram["model_matrix"].SetValue(Matrix4.Identity); //Ustawienie macierzy swiata shaderProgram["enable_lighting"].SetValue(lighting); shaderProgram["illuminance"].SetValue(natezenieSwiatla); shaderProgram["lightdirX"].SetValue(kierunekSwiatlaX); shaderProgram["lightdirY"].SetValue(kierunekSwiatlaY); shaderProgram["lightdirZ"].SetValue(kierunekSwiatlaZ); obiekt = new ObjLoader(objPath, shaderProgram); //Stworzenie obiektu za pomoca klasy ObjLoader watch = System.Diagnostics.Stopwatch.StartNew(); //Rozpoczecie Stopwatcha potrzebnego do obrotow kamery czy z klawi. czy za pomoca myszy Glut.glutMainLoop(); //start glownej petli Glut } else { MessageBox.Show("Zamknąłeś aplikację bez nadania ścieżki do obiektu,\r\nOpenGL nie może się uruchomić.", "Błąd inicjacji."); } }