Beggining OpenGL -

Sup guys,

I decided to multi-task and learn Win32 and OpenGL at the same time. Obviously I'm going to start of with some questions -

#include <windows.h>
#include <GL/gl>
#include <GL/glu>
#include <GL/glaux>

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
glBegin( GL_TRIANGLES );
glColor3f(1.0, 0.0, 0.0, 1.0); // Sets current primary color to red
glVertex3f( 0.f, 0.f, 0.f ); // Specify three vertices
glVertex3f( 1.f, 0.f, 0.f );
glVertex3f( 0.f, 1.f, 0.f );
glEnd();

return 0;
}

I understand pretty much everything there except for how do I use WM_PAINT to display the thing up there?

Thanks.
[786 byte] By [.pcbrainbuster] at [2007-11-20 10:55:27]
# 1 Re: Beggining OpenGL -
http://nehe.gamedev.net/

There are a number of lessons. Each lesson has code for different
systems.
Philip Nicoletti at 2007-11-9 1:24:43 >
# 2 Re: Beggining OpenGL -
Here's a portable OpenGL abstraction,

http://g3d-cpp.sourceforge.net/
_uj at 2007-11-9 1:25:43 >
# 3 Re: Beggining OpenGL -
Thanks for your posts guys! But I like to work with the "original" if you know what I mean which is why I have to work with OpenGL itself or DirectX.

Philip Nicoletti: I'll know be checking your link out

Everyone else: While I'm doing that could someone just give me an example of how to get that code above into a window?

Thanks.
.pcbrainbuster at 2007-11-9 1:26:43 >
# 4 Re: Beggining OpenGL -
I checked out the link and decided that site just has to much fat, I mean that it expects yoo to copy and paste to much :(.

Can anyone please just explain here and now?

Thanks.
.pcbrainbuster at 2007-11-9 1:27:45 >
# 5 Re: Beggining OpenGL -
I understand pretty much everything there except for how do I use WM_PAINT to display the thing up there?

You don't. OpenGL, indeed all 'graphics' APIs have their own drawing functions.
Greggle at 2007-11-9 1:28:51 >
# 6 Re: Beggining OpenGL -
Grrr! How would I then actually draw that code?

Thanks.
.pcbrainbuster at 2007-11-9 1:29:50 >
# 7 Re: Beggining OpenGL -
A whole lot. There's going to be a lot of initializing and preparation. I don't remember who recommended it first(Nicoletti??), but go to nehe (http://nehe.gamedev.net/). That place has been around forever and it is the best(in my opinion) resource for OpenGL. I remember going there as far back as 2000.

The lessons will walk you through, step by step. They also have full code listings available for each lesson. And for pretty much every platform in the known world.
Greggle at 2007-11-9 1:30:47 >
# 8 Re: Beggining OpenGL -
I also learned it from nehe, keep a copy of this book ( http://www.opengl.org/documentation/red_book/) aside for extra explanation (free html version available). I think its best you read the first chapter of this book before beginning, it will give you some global opengl understanding.
ejac at 2007-11-9 1:31:56 >
# 9 Re: Beggining OpenGL -
Greggle - Thanks for the link, but it is so annoying! Its just an example yet they have to use extra functions and things when it really shouldn't be used, I don't even understand what they did to make the program full screen, do you mind giving me an example by editing the following code? -

#include <windows>

const char *ClsName = "BasicApp";
const char *WndName = "A Simple Window";

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;

// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProc;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

// Register the application
RegisterClassEx(&WndClsEx);

// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application

// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HWND EC;

switch (Msg) {

case WM_DESTROY :
PostQuitMessage(WM_QUIT);
break;

}

return DefWindowProc(hWnd, Msg, wParam, lParam);
}

ejac - I read the HTML version and have yet to do further study/research/understanding before I post information/complaints :)/problems/complements about it.

Thanks.
.pcbrainbuster at 2007-11-9 1:32:53 >
# 10 Re: Beggining OpenGL -
ejac - I hate this site too as it simply uses Glut which is something I don't have! How do I get it?

Thanks!
.pcbrainbuster at 2007-11-9 1:33:56 >
# 11 Re: Beggining OpenGL -
I hate this site too as it simply uses Glut which is something I don't have! How do I get it?

euh, first link when you google "glut": http://www.xmission.com/~nate/glut.html

If your running windows, download the zip. Put the .h in an include folder (or usually a new subfolder named "GL"), link the .lib in your project settings, and put the .dll where the .exe is compiled to.
ejac at 2007-11-9 1:34:55 >
# 12 Re: Beggining OpenGL -
How do I link the file?
.pcbrainbuster at 2007-11-9 1:36:01 >
# 13 Re: Beggining OpenGL -
Actually I'm not sure if I should work with OpenGL or DirectX, what do you ot think I should do?
.pcbrainbuster at 2007-11-9 1:36:57 >
# 14 Re: Beggining OpenGL -
How do I link the file?what compiler/IDE are you using?

Actually I'm not sure if I should work with OpenGL or DirectXThere is a lot written on "directx vs opengl", it comes down to personal preference. With that question you can start a serious flamewar :). Google it, read it, and decide for yourself. I learned opengl because I was thought at school, and they use it for its portability (i think they do at most univs).
I never coded directx, but my guess is that opengl/glut combo is the easiest to learn. (by which i mean there is the least amount of lines of code to get a window up and draw some stuff in there)
ejac at 2007-11-9 1:38:03 >
# 15 Re: Beggining OpenGL -
I'm using Borland C++ Builder 6.

Actually I chose OpenGL because it is/and looks easier...

Thanks.
.pcbrainbuster at 2007-11-9 1:39:02 >
# 16 Re: Beggining OpenGL -
hmm, never used borland c++, but i guess its somewhat the same as others. Find project properties (build configuration), then find linker settings, then find where to add additional libraries (usually there are already some there), then add fullpath\glut.lib (or use some environment variable, or add path to additional library paths, just be sure borland is able to find it). And then you should be able to compile and link.
ejac at 2007-11-9 1:39:57 >
# 17 Re: Beggining OpenGL -
I found the library folder and put the .lib file in there but when I compiled the program it just gave a linker error.

What should I do?

Thanks.
.pcbrainbuster at 2007-11-9 1:41:02 >
# 18 Re: Beggining OpenGL -
You still have to tell the linker it should link to that lib file. See my last post on that.

With "just be sure borland is able to find it", i meant if you only say it has to link to "glut.h", it has to know in which path to search.
So easiest is to link to something like:
"c:\project\lib\glut.lib"
ejac at 2007-11-9 1:42:07 >
# 19 Re: Beggining OpenGL -
Sadly it still does not work. I think in my case the best thing to do would be to simply find a tutorial that focuses on plain OpenGL.

Questions -
1) What sites offer "pain" OpenGL tutorials?
2) What sites explain how to work with Device Contexts and such?

(I did use Google).

Thanks.
.pcbrainbuster at 2007-11-9 1:43:01 >
# 20 Re: Beggining OpenGL -
From the red book 1st chapter:
OpenGL programs have to use the underlying mechanisms of the windowing system A little further:
The OpenGL Utility Toolkit (GLUT) is a window system-independent toolkit, written by Mark Kilgard, to hide the complexities of differing window system APIs
So you use win32 or you use some other library (which makes use of win32 but are usually more intuitive) like GLUT.
If you'ld use visual studio 2005 express (free version), I can surely help you.

even more explanation in chapter one:
As you know, OpenGL contains rendering commands but is designed to be independent of any window system or operating system. Consequently, it contains no commands for opening windows or reading events from the keyboard or mouse. Unfortunately, it's impossible to write a complete graphics program without at least opening a window, and most interesting programs require a bit of user input or other services from the operating system or window system. In many cases, complete programs make the most interesting examples, so this book uses GLUT to simplify opening windows, detecting input, and so on. If you have an implementation of OpenGL and GLUT on your system, the examples in this book should run without change when linked with them.

As you see, besides this, there is really essential and basic know how in that chapter (and the others to ofcourse). You wont find a better introduction.
ejac at 2007-11-9 1:44:07 >
# 21 Re: Beggining OpenGL -
Actually I did read the whole first chapter. But the Glut thing isn't working for me :(
.pcbrainbuster at 2007-11-9 1:45:08 >
# 22 Re: Beggining OpenGL -
But the Glut thing isn't working for me

If you cant get it to work, you'll never get any library to work. They all follow the same principle: include the .h file, link to the .lib file, and make sure the .exe sees the .dll file.

So you search borland help/forum or something until you find how to tell its linker to link to a lib, or you download/install VS2005 express and then you can get a step by step howto. Or you use a command line compiler like gcc, and learn about makefiles and compile it that way. Either way, you'll have to learn how to use a library someday if you intend to make realworld/usefull programs someday.

btw: from reading your other post i see your using win32, that project also has to use libraries just like glut, but borland probably makes a project for you with all set.
ejac at 2007-11-9 1:46:06 >
# 23 Re: Beggining OpenGL -
Thanks for your post! Though I'll have to try/look/find info in the morning and can't now.

Thanks.
.pcbrainbuster at 2007-11-9 1:47:09 >