private static void InitLines() { int i; Point newborn; Random random = new Random(); firstX *= step; firstY *= step; secondX *= step; secondY *= step; for (i = 0; i < points; i++) { newborn = new Point(); newborn.Next = first; newborn.X = -1.0f; newborn.Y = -1.0f; first = newborn; } newborn = first; while (newborn.Next != null) { newborn = newborn.Next; } newborn.Next = first; first.X = random.Next() % Glut.glutGet(Glut.GLUT_WINDOW_WIDTH); first.Y = random.Next() % Glut.glutGet(Glut.GLUT_WINDOW_HEIGHT); for (i = 0; i < points; i++) { newborn = new Point(); newborn.Next = second; newborn.X = -1.0f; newborn.Y = -1.0f; second = newborn; } newborn = second; while (newborn.Next != null) { newborn = newborn.Next; } newborn.Next = second; second.X = random.Next() % Glut.glutGet(Glut.GLUT_WINDOW_WIDTH); second.Y = random.Next() % Glut.glutGet(Glut.GLUT_WINDOW_HEIGHT); }
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 <uint>(new uint[] { 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()))); } watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
// --- Callbacks --- #region Display() /// <summary> /// Called to draw the client area. /// </summary> private static void Display() { int buffer = 0; float[] p = lightPosition; // get the current color buffer being drawn to Gl.glGetIntegerv(Gl.GL_DRAW_BUFFER, out buffer); // clear the color and depth buffer Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glPushMatrix(); Gl.glRotatef(angle1 += increment, 0.0f, 1.0f, 0.0f); // set the position of the light Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, lightPosition); // switch to viewpoint of light Gl.glPushMatrix(); // disable drawing into color buffer Gl.glDrawBuffer(Gl.GL_NONE); // set the camera to the viewpoint of the light Gl.glLoadIdentity(); Glu.gluLookAt(p[0], p[1], p[2], 0, 0, 0, 0, 1, 0); // draw scene Render(); // save the depth buffer Gl.glReadPixels(0, 0, windowWidth, windowHeight, Gl.GL_DEPTH_COMPONENT, Gl.GL_FLOAT, depthLight); // enable drawing into color buffer Gl.glDrawBuffer(buffer); Gl.glPopMatrix(); // clear the depth buffer Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT); // draw scene Render(); // draw the shadow Shadows(); Gl.glPopMatrix(); Gl.glFlush(); Glut.glutSwapBuffers(); }
private static void OnRenderFrame() { watch.Stop(); float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency; watch.Restart(); // set up the viewport and clear the previous depth and color buffers Gl.Viewport(0, 0, width, height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // perform rotation of the cube depending on the keyboard state if (autoRotate) { xangle += deltaTime / 2; yangle += deltaTime; } if (right) yangle += deltaTime; if (left) yangle -= deltaTime; if (up) xangle -= deltaTime; if (down) xangle += deltaTime; // make sure the shader program and texture are being used Gl.UseProgram(program); Gl.ActiveTexture(TextureUnit.Texture1); Gl.BindTexture(brickNormals); Gl.ActiveTexture(TextureUnit.Texture0); Gl.BindTexture(brickDiffuse); // set up the model matrix and draw the cube program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle)); program["enable_lighting"].SetValue(lighting); program["enable_mapping"].SetValue(normalMapping); Gl.BindBufferToShaderAttribute(pyramid, program, "vertexPosition"); Gl.BindBuffer(pyramidTriangles); // draw the pyramid Gl.DrawElements(BeginMode.Triangles, pyramidTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition"); Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal"); Gl.BindBufferToShaderAttribute(cubeTangents, program, "vertexTangent"); Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV"); Gl.BindBuffer(cubeTriangles); Gl.DrawElements(BeginMode.Triangles, cubeTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Glut.glutSwapBuffers(); }
private void Form1_Load(object sender, EventArgs e) { float[] LightAmbient = { 0.5f, 0.5f, 0.5f, 1.0f }; float[] LightDiffuse = { 1.0f, 1.0f, 1.0f, 1.0f }; float[] LightDirection = { 0.0f, 0.0f, 1.0f, 0.0f }; // инициализация Glut Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_SINGLE | Glut.GLUT_DEPTH); // отчитка окна Gl.glClearColor(255, 255, 255, 1); // установка порта вывода в соответствии с размерами элемента anT Gl.glViewport(0, 0, AnT.Width, AnT.Height); // настройка проекции Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); float delta = AnT.Width / (float)AnT.Height; Gl.glOrtho(-5.0 * delta, 5.0 * delta, -5.0, 5.0, -50, 50); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); Gl.glEnable(Gl.GL_DEPTH_TEST); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, LightDiffuse); Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT, LightAmbient); Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, LightDirection); Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, LightDirection); Gl.glEnable(Gl.GL_NORMALIZE); Gl.glLightModelf(Gl.GL_LIGHT_MODEL_TWO_SIDE, Gl.GL_TRUE); Gl.glEnable(Gl.GL_LIGHT1); Gl.glEnable(Gl.GL_LIGHT0); /* MessageBox.Show("Выберите файл .obj"); * if (openFileDialog1.ShowDialog() == DialogResult.Cancel) * return; * string fileName = openFileDialog1.SafeFileName; * string fullFileName = openFileDialog1.FileName; * labelFile.Text = fileName; * figure = new Figure(ref AnT, fullFileName); * comboBoxProjection.SelectedIndex = 1; * figure.Draw();*/ }
public static void Execute() { Glut.glutInit(); Glut.glutInitWindowPosition(100, 100); Glut.glutInitDisplayMode(Glut.GLUT_RGB); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Task3"); Glut.glutDisplayFunc(Display); //Glut.glutIdleFunc(Display); //Glut.ReshapeFunc(Reshape); //Glut.glutKeyboardFunc(Keyboard); Glut.glutMouseFunc(Mouse); Init(); Glut.glutMainLoop(); }
public void SetMainLoop() { //отлов действий пользователя Glut.glutMotionFunc(ClickedMotion); Glut.glutMouseFunc(Mouse); Glut.glutPassiveMotionFunc(PassiveMotion); Glut.glutKeyboardFunc(Key); Glut.glutKeyboardUpFunc(KeyUp); Glut.glutSpecialFunc(KeySpecial); Glut.glutSpecialUpFunc(KeySpecialUp); //старт игрового цикла Glut.glutTimerFunc(Config.TimePerFrame, MainProcess, 0); Glut.glutMainLoop(); }
private static void Idle() { currentTime = Environment.TickCount; timeElapsed = currentTime - oldTime; secondsPerFrame = timeElapsed / 1000.0f; waterOffset += secondsPerFrame / 2.0f; if (waterOffset >= 1.0f) { waterOffset -= 1.0f; } // Environment.TickCount's resolution and latency isn't really good enough for this, so I'm manually setting a value movementValue = (float)desiredDistance * secondsPerFrame + 0.2f; Glut.glutPostRedisplay(); oldTime = currentTime; }
public static void DrawPlate3D(double xpos, double ypos, double xang, double yang, double zang, RGBAColor col) { glColor4d(col.Mix(col, new RGBAColor(0, 0, 0, 1), 0.2)); Gl.glPushMatrix(); Gl.glTranslated(xpos, ypos, 0.7); Gl.glRotated(xang, 1, 0, 0); Gl.glRotated(yang, 0, 1, 0); Gl.glRotated(zang, 0, 0, 1); Gl.glScaled(0.7, 0.1, 0.7); Glut.glutSolidCube(1); Gl.glLineWidth(2); glColor4d(col); Glut.glutWireCube(1); Gl.glPopMatrix(); }
//параметры окна OpenGL public void init() { //Gl.glutInit(); /* установим черный фон */ Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB); Glut.glutInitWindowSize(1000, 1000); Glut.glutInitWindowPosition(100, 200); Glut.glutCreateWindow("SERVER"); Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* инициализация viewing values */ Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0, 1000, 1000, 0, -1, 1); }
private void CreateDisplayList() { // генерация дисплейног осписка DisplayListNom = Gl.glGenLists(1); float[] Color = { 1f, 0.7f, 0.7f, .5f }; // начало создания списка Gl.glNewList(DisplayListNom, Gl.GL_COMPILE); // Gl.glColor3b(0, 0, 255); // Gl.glColor3d(0, 0, 255); Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT_AND_DIFFUSE, Color); Glut.glutSolidSphere(0.01f, 10, 10); Gl.glEndList(); // флаг - дисплейный список создан isDisplayList = true; }
private void OnKeyboardDown(byte key, int x, int y) { player.KeyInput(key); if (key == 'l') { map.ResizeMap(false); Console.WriteLine("Py Pos: " + (map.mapY + player.position.Z)); } if (key == 27) { Glut.glutLeaveMainLoop(); } }
// Main Starts static void Main(string[] args) { Glut.glutInit(); // Initialize glut // Setup display mode to double buffer and RGB color Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB); // Set the screen size Glut.glutInitWindowSize(1200, 700); Glut.glutCreateWindow("OpenGL 3D Navigation Program With Tao"); init(); Glut.glutReshapeFunc(reshape); Glut.glutDisplayFunc(drawings); // Set window's key callback Glut.glutKeyboardFunc(new Glut.KeyboardCallback(keyboard)); Glut.glutMainLoop(); }
static void Desenha() { Gl.glPushMatrix(); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); DesenhaQuadra(); HasteCesta1(); Tabela1(); Cesta1(); HasteCesta2(); Tabela2(); Cesta2(); Bola(); Gl.glPopMatrix(); Glut.glutSwapBuffers(); }
private static void OnMouse(int button, int state, int x, int y) { // this method gets called whenever a new mouse button event happens if (button == Glut.GLUT_RIGHT_BUTTON) mouseDown = (state == Glut.GLUT_DOWN); // if the mouse has just been clicked then we hide the cursor and store the position if (mouseDown) { Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE); downX = x; downY = y; } else // unhide the cursor if the mouse has just been released Glut.glutSetCursor(Glut.GLUT_CURSOR_LEFT_ARROW); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DEPTH | Glut.GLUT_DOUBLE | Glut.GLUT_RGB); Glut.glutInitWindowSize(600, 600); Glut.glutInitWindowPosition(100, 100); Glut.glutCreateWindow("Desvie dos obstaculos"); Inicializa(); Gl.glEnable(Gl.GL_DEPTH_TEST); Glut.glutDisplayFunc(Desenha); Glut.glutSpecialFunc(TeclasBola); Glut.glutTimerFunc(50, MoverPedra, 1); luz(); Glut.glutMainLoop(); }
public static void DrawString(double x, double y, string str, RGBAColor col, double depth = -1.0) { UpdateDepth(depth); Gl.glPushMatrix(); Gl.glTranslated(x, y, currentdepth); Gl.glScaled(0.10, 0.10, 1.0); Gl.glLineWidth(1); Gl.glColor3d(col.R, col.G, col.B); foreach (char c in str) { Gl.glTranslated(10, 0.0, 0.0); Glut.glutStrokeCharacter(Glut.GLUT_STROKE_ROMAN, c); } Gl.glPopMatrix(); }
//функция, обрабатывающая значения с клика мыши public void MousePressed(int button, int state, int ax, int ay) { down = button == Glut.GLUT_LEFT_BUTTON && state == Glut.GLUT_LEFT; //ЕСЛИ НАЖАТА (И НЕ ЗАЖАТА) ЛЕВАЯ КЛАВИША МЫШИ if (down && (count) == 1) { Glut.glutPostRedisplay(); start = true; //начинаем игру mx = ax; //назначаем переменной координату мыши по х my = ay; //назначаем переменной координату мыши по у if (checkMouse(mx, my)) { pp = true; } } }
private static void Keyboard(byte key, int x, int y) { switch (key) { case 27: Environment.Exit(0); break; case (byte)'c': case (byte)'C': showPoints = !showPoints; Glut.glutPostRedisplay(); break; } }
/// <summary> /// /// </summary> public void render() { this.clear(); Camera.getCurrentActiveCamera().set(); this.renderLighting(); this.renderAtmosphere(); this.renderMap(); this.renderSceneObjects(); this.displayMessageQueue(); Glut.glutSwapBuffers(); }
public static void PrintGL(double x, double y, string str, double size = 5) { Gl.glPushMatrix(); Gl.glTranslated(x, y, 0); Gl.glLineWidth((float)(0.2 * size)); double sz = 0.005f * size; Gl.glScaled(sz, sz, sz); for (int c = 0; c < str.Length; c++) { Glut.glutStrokeCharacter(Glut.GLUT_STROKE_ROMAN, (int)str[c]); } Gl.glPopMatrix(); }
public GlControl(int Width, int Height) { // // TODO: Add constructor logic here // this.width = Width; this.height = Height; Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(Width, Height); Glut.glutInitWindowPosition(0, 0); Glut.glutCreateWindow("Tarea OpenGL"); // Glut.glutReshapeFunc(new Glut.ReshapeCallback(this.myReshape)); Init(); }
private static void rc_CubeRotationEvent(object sender, CubeRotationEventArgs args) { //throw new NotImplementedException(); //crArgs = args; //rcPrev = new RubiksCube((RubiksCube)sender); crArgs.Enqueue(args); rcOld.Enqueue(new RubiksCube((RubiksCube)sender)); isERArgs.Enqueue(false); if (rcOld.Count == 1) { Glut.glutDisplayFunc(DisplayCubeRotation); } Glut.glutPostRedisplay(); //Glut.glutMainLoopEvent(); }
public OpenGLAdapter(SimpleOpenGlControl viewport) { _viewport = viewport; _viewport.InitializeContexts(); Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Gl.glClearColor(255, 255, 255, 1); Gl.glViewport(0, 0, _viewport.Width, _viewport.Height); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Glu.gluOrtho2D(0, _viewport.Height, 0, _viewport.Width); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); }
private static void RenderQuads() { Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glLoadIdentity(); Gl.glBegin(Gl.GL_QUADS); Gl.glColor3f(0.0f, 0.0f, 0.0f); Gl.glVertex2f(-0.5f, -0.5f); Gl.glColor3f(0.0f, 0.0f, 0.0f); Gl.glVertex2f(-0.5f, 0.5f); Gl.glColor3f(0.0f, 0.0f, 0.0f); Gl.glVertex2f(0.5f, 0.5f); Gl.glColor3f(0.0f, 0.0f, 0.0f); Gl.glVertex2f(0.5f, -0.5f); Gl.glEnd(); Gl.glFlush(); Glut.glutSwapBuffers(); }
static void Redraw() { Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); Gl.glPushMatrix(); Axis3D.DrawAxis(); FigureMotion(); DrawSquad(); Gl.glPopMatrix(); Glut.glutSwapBuffers(); CalculateNewFigureSize(); }
public Form1() { InitializeComponent(); simpleOpenGlControl1.InitializeContexts(); Glut.glutInit(); //sp.PlayLooping(); currentTime = System.DateTime.Now; this.Text = hour.ToString() + ":" + min.ToString() + ":" + sec.ToString(); sec = currentTime.Second; min = currentTime.Minute; hour = currentTime.Hour; }
static private void parsekey(byte key, int x, int y) { int k = Convert.ToInt32(key.ToString()); switch (k) { case 27: for (int i = 0; i < 6; ++i) { fonts[i].Destroy(); } System.Environment.Exit(0); break; case 13: if (mode == mode_t.EDITING) { mode = mode_t.INTERACTIVE; } else { mode = mode_t.EDITING; } break; case 32: current_font++; if ((int)current_font > 5) { current_font = 0; } break; default: byte[] tmp = new byte[1]; tmp[0] = key; if (mode == mode_t.INTERACTIVE) { myString = System.Text.Encoding.ASCII.GetString(tmp); } else { myString += System.Text.Encoding.ASCII.GetString(tmp); } break; } Glut.glutPostRedisplay(); }
// This function is used for the navigation keys public static void keyboard(byte key, int x, int y) { switch (key) { // x,X,y,Y,z,Z uses the glRotatef() function case 120: // x // Rotates screen on x axis rotX -= 2.0f; break; case 88: // X // Opposite way rotX += 2.0f; break; case 121: // y // Rotates screen on y axis rotY -= 2.0f; break; case 89: // Y // Opposite way rotY += 2.0f; break; case 122: // z // Rotates screen on z axis rotZ -= 2.0f; break; case 90: // Z // Opposite way rotZ += 2.0f; break; case 111: // o // Resets all parameters case 80: // O // Displays the cube in the starting position rotation = false; X = Y = 0.0f; Z = 0.0f; rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; rotLx = 0.0f; rotLy = 0.0f; rotLz = 0.0f; Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); Glu.gluLookAt(rotLx, rotLy, 15.0f + rotLz, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); break; } Glut.glutPostRedisplay(); // Redraw the scene }
private static void OnKeyboardUp(byte key, int x, int y) { if (key == 'w') { up = false; } else if (key == 's') { down = false; } else if (key == 'd') { right = false; } else if (key == 'a') { left = false; } else if (key == 'e') { eKey = false; } else if (key == 'q') { qKey = false; } else if (key == 'r') { moveSpeed = 3; } else if (key == 'l') { lighting = !lighting; } else if (key == 'f') { fullscreen = !fullscreen; if (fullscreen) { Glut.glutFullScreen(); } else { Glut.glutPositionWindow(0, 0); Glut.glutReshapeWindow(1280, 720); } } }