1 / 11

Introduction to GL

This guide introduces the basics of OpenGL and GLUT by demonstrating how to create a simple window displaying a green square. It covers essential functions such as `glutInit`, `glutInitDisplayMode`, and setting up display parameters. The tutorial provides a practical example, explaining window setup, color initialization, and matrix configurations. Additionally, it outlines how to define a drawing routine and initiate the main loop for rendering. Whether you're a beginner or looking to refresh your skills, this guide offers a concise introduction to graphical programming.

Download Presentation

Introduction to GL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to GL Geb Thomas

  2. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(100,100); glutInitWindowSize(300,300); glutCreateWindow ("square"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glutDisplayFunc(display); glutMainLoop(); return 0; void display(void) { glClear( GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(2.0, 4.0, 0.0); glVertex3f(8.0, 4.0, 0.0); glVertex3f(8.0, 6.0, 0.0); glVertex3f(2.0, 6.0, 0.0); glEnd(); glFlush(); }

  3. What’s Going On? • OpenGL – The graphics calls • GLUT – Utility for opening windows • Both have header files and libraries • Opengl32.dll, glut32.dll • opengl.h, glut32.h

  4. Using GLUT To Initialize the Display glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);

  5. Setting Up and Opening the Window glutInitWindowPosition(100,100); glutInitWindowSize(300,300); glutCreateWindow ("square");

  6. Setting Up the Matrices glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0);

  7. Defining the Drawing Routine glutDisplayFunc(display);

  8. Drawing Some Stuff void display(void) { glClear( GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(2.0, 4.0, 0.0); glVertex3f(8.0, 4.0, 0.0); glVertex3f(8.0, 6.0, 0.0); glVertex3f(2.0, 6.0, 0.0); glEnd(); glFlush(); }

  9. Repeating the Loop glutMainLoop();

  10. Details are Here www.opengl.org Good book: Open GL Programmer’s Guide

More Related