Window reshaping, Keyboard interaction, Camera, Drawing objects OpenGL & GLUT Basics Window reshaping, Keyboard interaction, Camera, Drawing objects George Georgiev Telerik Corporation www.telerik.com
Table of Contents Project using OpenGL & FreeGLUT in MSVC++ Window reshaping Keyboard Interaction Camera Positioning, orientation Drawing objects Coloring Basic Lighting
Project using OpenGL & FreeGLut A reminder…
OpenGL & FreeGLUT Project Step 1 – Creating the project Setup OpenGL & FreeGLUT (done only once) Open Visual Studio, Choose C++ as a language Create a Win32 Console application Tick “Empty project” Add a new .cpp file #include <gl\glew.h> #include <gl\freeglut.h> int main(int argc, char ** argv)
OpenGL & FreeGLUT Project (2) Step 2 - Linking Go to Project > [YourProjectName] Properties From the side menu choose Configuration properties > Linker > Input In the Additional Dependencies type in: glew32.lib freeglut.lib Do this for both Debug and Release configurations (upper left corner in the window) Close the properties window, you’re ready to go
OpenGL & FreeGLUT Project (2) Tip – the faster way to link to the libraries Skip the entire Step 2 In the .cpp file write: #pragma comment (lib, “glew32.lib”) #pragma comment (lib, “freeglut.lib”)
Window reshaping The Reshape function
Window reshaping Reshape function Specified by glutReshapeFunc Defines how your window reshapes Write it once, remember it no more
Window reshaping Live Demo * (c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*
The Keyboard monitoring functions Keyboard interaction The Keyboard monitoring functions
Keyboard interaction Keyboard monitoring functions Specified by glutKeyboardFunc glutKeyboardUpFunc Monitor key pressing and key releasing Doesn’t receive device information Receives translated windows messages
Keyboard interaction Live Demo * (c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*
Orientation and positioning Camera control Orientation and positioning
Camera control ‘Moving the world’ method Using the gluLookAt function Using the glTranslate* and glRotate* functions You do the things the opposite way around F. e., to move the camera forward, move the objects backward Using the gluLookAt function Specifies camera location Viewed location
GLUT predefined objects, Coloring, Positioning Drawing objects GLUT predefined objects, Coloring, Positioning
Drawing objects GLUT predefined functions Coloring Positioning glutSolid* glutWireframe* Coloring glColor* - defines the current drawing color Positioning glTranslate* - moves the renderer by a vector glRotate* - rotates the renderer by an Euler angle
Camera control & Drawing objects * Camera control & Drawing objects Live Demo (c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*
Basic Lighting Enabling lighting
Basic lighting Enabling lighting glEnable Enabling ‘color material’
Basic Lighting Live Demo * (c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*
OpenGL Basics ? ? ? ? ? Questions? ? ? ? ? ? ?