Download presentation
Presentation is loading. Please wait.
Published bySharlene Dean Modified over 8 years ago
1
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
2
Review of papers OpenGL – brief intro OpenGL programming Licensing details last slide
3
EEE4084F Image source: The Strange Evolution of OpenGL Part 1
4
Towards OpenGL Programming EEE4084F To help prepare you for Prac5…
5
In OpenGL geometric objects are described with vertices A vertex is a collection of generic attributes (not just the 3D position!), these aggregate: Position coordinates : these are 4-dimensional homogeneous coordinates Colors Texture coordinates Other data associated with that point Vertices / GL_POINTS VBOs and VAOs: VBOs: vertex data stored in Vertex Buffer Objects VAOs: Vertex Array Object (VAO) stores a list of VBOs Locations can be 2D, 3D or 4D (i.e. you can draw a 2D scene) Homogeneous coordinates? These are used to calculate perspective, representing one frame (e.g. the scene) in terms of another (e.g. camera viewpoint). The projection transformation essentially maps scene coordinates to viewpoint coordinates.
6
The primitives are specified by vertices GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_POINTS
7
OpenGL programming tends to follow the following approach: 1. Create shader programs 2. Create buffer objects and load data into them 3. Connect data locations with shader variables 4. Render
8
OpenGL applications need to render the results somewhere; Can render to the visible (onscreen window) or Render to a hidden window (e.g. image or framebuffer which can become visible) This is where The GLUT is useful… GLUT = OpenGL Utility Toolkit GLUT is basically an abstracted window library (another API) that has implementations that connect to the underlying O/S Functions to create windows, get user input (e.g. key presses and mouse movements) and the like.
9
OpenGL Programming: Simple Starting Point EEE4084F
10
Includes (of etc.) Main function / WinMain : Create a window (if using Win32) Link OpenGL renderer to the window While 1 loop: Check for messages (handle inputs) Update scene
11
/************************** * Includes **************************/ #include /************************** * WinMain * **************************/ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; HWND hWnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; float theta = 0.0f; /* register window class */ wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "GLSample"; RegisterClass (&wc); /* create main window */ hWnd = CreateWindow ( "GLSample", "OpenGL Sample", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0, 0, 256, 256, NULL, NULL, hInstance, NULL); /* enable OpenGL for the window */ EnableOpenGL (hWnd, &hDC, &hRC); /* program main loop */ while (!bQuit) { /* check for messages */ if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { /* handle or dispatch messages */ if (msg.message == WM_QUIT) bQuit = TRUE; else { TranslateMessage (&msg); DispatchMessage (&msg); } else { /* OpenGL animation code goes here */ } } /* end while */ /* shutdown OpenGL */ DisableOpenGL (hWnd, hDC, hRC); DestroyWindow (hWnd); /* destroy the window explicitly */ return msg.wParam; } Setting up the window Create the Windows (Win32 code) Event handler (this is technically using Win32 not GLUT) Shutdown (when window closed or exit pressed) Draw the scene
12
/* OpenGL animation code goes here */ glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClear (GL_COLOR_BUFFER_BIT); glPushMatrix (); glRotatef (theta, 0.0f, 0.0f, 1.0f); glBegin (GL_TRIANGLES); glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f); glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.87f, -0.5f); glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.87f, -0.5f); glEnd (); glPopMatrix (); SwapBuffers (hDC); Clear drawing colour, clear frame buffer Saves current context, rotational settings etc. Rotate screen to theta * * see earlier code … this says how the scene will be totated Specify the points of a shape and the colour of these shapes, the system will then apply a gradient shading between these points End of the shape description Restore previous context Swap working and visible buffer
13
Any guesses as to what will be displayed?
14
L05 - 05751939 - Fermi GF100 GPU Architecture.pdf L05 - 06332118 - Augmented Reality Environment for Learning OpenGL
15
If you use your own laptop/PC for pracs: Try getting OpenGL installed on your machine. For Windows Code::Blocks and DevC++ provides OpenGL projects (takes a bit of time setting it up on Code::Blocks)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.