You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- Basic OpenGL Application
 


How to make a Simple OpenGL Application Page 2 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

Adding Source Code Files

Lets add a source code file now. Open File-New and pick "C++ Source File" and name it "main" (that's just what I like to name my main file, name it whatever you like). Then go back into File-New and add a "C/C++ Header File" and name it "main". These are all the files you'll need for now.

Look around for a FileView tab, it should be on the sidebar on your left. If you can't find it, hit Alt+0 (Alt Zero) to bring it up. Double click the "main.cpp" file. Then add to the top of this file this line:

#include "main.h"

For now lets leave it at that. Now open the "main.h" file. Quick Tip: right-click the #include line you just entered and choose 'Open Document "main.h"'.

Add the following #include lines to "main.h". I'm not sure that they're all necessary, but you'll probably need them eventually.

// Windows includes
#include <windows.h>
#include <wingdi.h>
#include <winuser.h>

#include <stdlib.h>
#include <stdio.h>

// OpenGL includes
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

#include <string.h> // string-related functions
#include <time.h>   // time-related functions
#include <math.h>   // math functions (sin, cos, etc.)


Add these lines to define our main windows functions

int APIENTRY WinMain(HINSTANCE hCurrentInst, 
                     HINSTANCE hPreviousInst, 
                     LPSTR lpszCmdLine, 
                     int nCmdShow);

LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, 
                       WPARAM wParam, LPARAM lParam);

HWND CreateOpenGLWindow(char* title, 
                        int x, int y, 
                        int width, int height);


Add these lines to globally define our main functions. What each one does is obvious to its name. Init() is called after the window is created but before we enter our main loop (more on this later). Resize(int w, int h) is called each time the user resizes our window. Display() handles drawing everything using OpenGL commands. Finally, Idle() is for calculating stuff like moving objects, collision detection, and other game-related stuff.

void Init();
void Resize(int w, int h);
void Display();
void Idle();

Update 11-14-99: Found that these lines are needed to get rid of a lot of useless warnings. Add these two lines to "main.h":

// disable useless conversion warnings

#pragma warning (disable:4244)
#pragma warning (disable:4305)

That's it for "main.h". Next Up: The Windows code.

How to make a Simple OpenGL Application Page 2 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!