Presentation is loading. Please wait.

Presentation is loading. Please wait.

UMBC GDC Programming Tutorial

Similar presentations


Presentation on theme: "UMBC GDC Programming Tutorial"— Presentation transcript:

1 UMBC GDC Programming Tutorial
Lesson 1 Understanding the basics of C++ Game Programming using OpenGL (and GLUT) This is geared toward getting your feet wet. Not jumping in.

2 Overview Why you're here What you'll be using Background of C++
What's different Getting started Get a working demo Add some code Review

3 Why? Get a grasp on the way of thinking.
Understand what makes it different from normal programming. Get experience with a graphics system. Get a sort of hello world working. To ask questions and interrupt me a lot.

4 Tool Set C++ Most game programming is still done in C++
Basic code is very similar to other high level languages OpenGL Works everywhere (Except XBOX 360) Exposes more of the background GLUT + cppgpgpu Get moving - fast.

5 C/C++ Background You #include definitions You write functions
You call functions from main You exit

6 Traditional C/C++ Program
#include <stdio.h> int AddTwoNumbers( int a, int b ) { return a + b; } int main() printf( “3 + 4 = %d\n”, AddTwoNumbers( a, b ); return 0;

7 C++ Classes Allow a level of abstraction, enabling:
Appearance as objects Classful function members Classful data members

8 C/C++ Function Pointers
Allows you to call a function dynamically Like any other pointer, but dereferences into call

9 What's Different? #include <stdio.h>
int AddTwoNumbers( int a, int b ) { return a + b; } int main() printf( “3 + 4 = %d\n”, AddTwoNumbers( a, b ); return 0;

10 So... Programming in larger systems requires a leap of faith
You are generally not in control of the main loop You must follow certain standards depending on your framework Code no longer remains linear

11 The Difference Start A B A Some kind of crazy engine sort of thing B

12 This Thing MyDraw main() GLUT Start Simple, huh?

13 Getting Started Make sure to open main.c in the main folder.
We will be going through the code in the order it appears Stuff in Orange Boxes is pertinent to lesson.

14 main.cpp overview (1) #include "GLUTCore.h" #include "OGLParts.h"
#include <stdio.h> void MyDraw(); Texture T1; Inclusion of Definitions Definition of Texture Object Function Prototype

15 main.cpp overview (2) int main (int argc, char * const argv[]) {
Function Definition int main (int argc, char * const argv[]) { printf("Hello, World!\n"); //This must be set before init. GLUT.SetDrawFunct( MyDraw ); GLUT.Init( argc, (char**)argv, 640, 480, "Hello World" ); //Enable Depth glEnable(GL_DEPTH_TEST); Debugging Set up Variables Initialize System Set Up Environment

16 (Note: All of this code only gets executed once)
main.cpp overview (3) //Load a texture from a file T1.LoadTextureFile( "Basic.ppm" ); GLUT.DrawAndDoMainLoop(); return 0; } Give up control Load an Image (Note: All of this code only gets executed once) Clean exit back to OS

17 main.cpp overview (4) void MyDraw() { //Clear the screen.
glClearColor( .1f, .1f, .2f, 0.0f ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); T1.ActivateTexture( 0 ); DrawSquare(); T1.DeactivateTexture( 0 ); Set up Rendering States Perform Render Action (Clear Screen) Perform Render Action (Draw Quad)

18 main.cpp overview (5) //Update FPS, print if its time. GLUT.TackFPS();
Tell system to perform function //Update FPS, print if its time. GLUT.TackFPS(); //You need these last two lines. glutSwapBuffers(); glutPostRedisplay(); } Swap front buffer with back buffer (cue to self: talk about double-buffering) Tell system to redraw at its own leisure

19 Let's add some code Modify the MyDraw() function.
Replace call to Enable/Disable Texture and DrawSquare(); with our own code Draw a single triangle in immediate mode

20 Added code T1.ActivateTexture( 0 ); DrawSquare();
Change Render State T1.ActivateTexture( 0 ); DrawSquare(); glBegin( GL_TRIANGLES ); glColor3f ( 1.0, 0.0, 0.0 ); glVertex3f( 0.0, 1.0, 0.0 ); glColor3f ( 0.0, 1.0, 0.0 ); glVertex3f( 1.0, 0.0, 0.0 ); glColor3f ( 0.0, 0.0, 1.0 ); glVertex3f( 0.0, 0.0, 0.0 ); glEnd(); T1.DeactivateTexture( 0 ); Vertex Attribute (R,G,B) Vertex Location (X,Y,Z)

21 Review Understand the difference from this and traditional programming
Have a basic understanding of this new type of program flow Have a working shape on your screen

22 Questions (last chance)
You know, I feel really bad about putting this image here, since I can't seem to find where it came from. The original source did not credit it.


Download ppt "UMBC GDC Programming Tutorial"

Similar presentations


Ads by Google