PDA

View Full Version : How do I start using OpenGL 3.0/3.1



Ray Tracer
05-10-2011, 12:02 AM
Hi folks,

Just planning to start coding using Visual C++ 2008 for some graphics drawing on a small project, one of my hobbies actually. Got books about OpenGL programming guide, C++ programming and a few others.

The hardware is Intel Q6600 and ATI Raedon 4870 1GB, know it's not a top end setup but i just need it to do some static graphics objects so should be okay.


The OS is Vista, again know it's not the best OS out there but can't afford to upgrade at the moment so live with it.


Got a bit rusty on VC++ and my first time to use OpenGL, where do I download OpenGL and how do I call the various commands?

Appreciate for your help!

Ray

Alfonse Reinheart
05-10-2011, 12:42 AM
You could try the tutorials in my signature. They use OpenGL 3.3, which your hardware should support with a driver update.

Ray Tracer
05-10-2011, 12:49 AM
Let me get this right, so you're saying the following code in your tutorial is already available without me doing any extra coding in my Main() function?

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);

glUseProgram(theProgram);

glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);

glDrawArrays(GL_TRIANGLES, 0, 3);

glDisableVertexAttribArray(0);
glUseProgram(0);

glutSwapBuffers();

Alfonse Reinheart
05-10-2011, 01:09 AM
Let me get this right, so you're saying the following code in your tutorial is already available without me doing any extra coding in my Main() function?

No. Unless you linked directly to this page (http://www.arcsynthesis.org/gltut/Basics/Tut01%20Dissecting%20Display.html) without reading a word before that, I don't know how you got that impression. And even then that doesn't make since, because the text above that source clearly says that this is the "display" function, not "main."

The page right before that page describes the layout of the tutorial, the interactions with FreeGLUT (which opens and manages the window), and where the actual "main" function is.

Ray Tracer
05-10-2011, 02:05 AM
Excuse me, I didn't express clearly about what I need.
I don't know how OpenGL works in a Windows environment.
Do I need to download anything so that I can use the OpenGL commands?
If there are downloads, where do I need to place them into and do I need to make it when I build my C++ object code?

You know...things like this I need to know in order to get my self up to speed.
Thanks!!

charliejay
05-10-2011, 02:54 AM
Just a summary:

Download the gl3.h header file from this website, not sure what else is required from memory, but you might need glext.h for the create context extension.

1) Make a window

2) Make a "standard" Windows OpenGL context
- this is the one that the operating system supports automatically
- automatically in this case means without you explicitly loading function pointers
- this gets you OpenGL 1.1 + extensions, or possibly OpenGL 1.4 + extensions on Vista/Win 7, as far as I know...

3) Load the function pointer that allows you to request an OpenGL 3 context
- I think it's WGL_ARB_create_context

4) Use that function to create a context of the required version

5) Once that succeeds, load function pointers for the GL version 3.x functions

6) Use them to draw stuff

Ray Tracer
05-10-2011, 03:05 AM
I see. So with just #include "glext.h" will do? You mean OpenGL libraries are built-in Windows, in my case Windows Vista?

Alfonse Reinheart
05-10-2011, 03:33 AM
There are two things you need (assuming you can create and manage windows in Win32): create an OpenGL context and load core and extension function pointers.

Detailed instructions for creating an OpenGL context (http://www.opengl.org/wiki/Creating_an_OpenGL_Context) are available. There are also a number of cross-platform toolkits (http://www.opengl.org/wiki/Related_toolkits_and_APIs#Toolkits_to_bridge_OpenG L_and_the_Window_System) available that abstract away window and context creation.

I would not suggest bothering with code for loading core/extension functions; there are plenty of extension loading libraries (http://www.opengl.org/wiki/Extension_Loading_Library) that you can use. They usually use their own headers, so you won't use glext.h, gl3.h, or gl.h; read the instructions for that library.

ZbuffeR
05-10-2011, 08:28 AM
Wanted to add the "Getting started" page from the GL wiki :
http://www.opengl.org/wiki/Getting_started