PDA

View Full Version : working with OGL 3.x



Pswin
08-14-2009, 02:36 PM
hi

i want to start working with OpenGL 3.x, and i have some questions?

1. how can i detcet the version of OGL driver before creating context?

2. how can i create OpenGL3.x context? ( in WIN32 and linux)

Ilian Dinev
08-14-2009, 03:21 PM
...
wglMakeCurrent(hDC,hRC); // from your existing code

// from now on, it's GL3.x initialization

PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddre ss("wglCreateContextAttribsARB");
if(!wglCreateContextAttribsARB){
MessageBoxA(0,"OpenGL3.0 not supported or enabled in NVemulate",0,0);
}else{
int attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};

HGLRC gl3Ctx = wglCreateContextAttribsARB(hDC, 0, attribs);
if(gl3Ctx){
wglDeleteContext(hRC);
hRC =gl3Ctx;
wglMakeCurrent(hDC,hRC);
//prints("opengl3 success");
//prints((char*)glGetString(GL_VERSION));
}else{
MessageBoxA(0,"OpenGL3.0 context did not init, staying in 2.1",0,0);
}
}

marshats
08-14-2009, 05:55 PM
1. to get the driver version try:


printf ("Version: %s\n", glGetString (GL_VERSION));


2. In linux to create an OpenGL3.x context, I use freeglut:



glutInit( &argc, argv );
glutInitContextVersion( 3, 0 );


This should be valid in windows also since freeglut is cross-platform but I am not a windows user so haven't tested it there.

You will have to use the Testing Release: Freeglut 2.6.0 Release Candidate 1 (http://freeglut.sourceforge.net/index.php#download) rather than the standard vanilla version. If you want to see more of how they actually do that under the hood, you could probably look at their code since it is open.

Dark Photon
08-14-2009, 07:58 PM
2. how can i create OpenGL3.x context? ( in WIN32 and linux)
For beginning OpenGL, definitely use freeglut as mentioned.

Thought if you'd rather glX/wgl, I can post you a short Xlib/glX code to create a GL window and GL3.x context in Linux.

Just let us know.

Pswin
08-14-2009, 10:42 PM
2. how can i create OpenGL3.x context? ( in WIN32 and linux)
For beginning OpenGL, definitely use freeglut as mentioned.

Thought if you'd rather glX/wgl, I can post you a short Xlib/glX code to create a GL window and GL3.x context in Linux.

Just let us know.

thanks, but i am not beginner in OpenGL. just i dont know features and changes of OGL 3.x and how to work with it.

zeoverlord
08-15-2009, 05:45 AM
thanks, but i am not beginner in OpenGL. just i dont know features and changes of OGL 3.x and how to work with it.

http://www.flashbang.se - for a few tutorials on how to switch to 3.x

for the rest you can read whats new in this (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&Board=12&page=1) forum section, it's not really that much new stuff, mainly it's a lot of ext stuff that went core like fbo texture arrays, geometry shaders, instancing, VAO, and so on.
The most important thing is what got removed.
As usual it's all in the registry (http://www.opengl.org/registry/).

Pswin
08-15-2009, 11:46 AM
good tutorial , thanks

Pswin
08-20-2009, 09:16 AM
how can i get opengl version before creating context and window?
( glGetString(GL_VERSION) dose not work before creating context)

(i need to get minor version for put it in the:
WGL_CONTEXT_MINOR_VERSION_ARB)

martinsm
08-20-2009, 10:13 AM
You can't. You need to create temporary window and context, if you need something like that.

Aleksandar
08-20-2009, 11:45 AM
...
(i need to get minor version for put it in the:
WGL_CONTEXT_MINOR_VERSION_ARB)
And be aware that although spec states that the previous implementations of OpenGL (<3.2) ignore WGL_CONTEXT_PROFILE_MASK_ARB attribute, I have realized that it is not (always) true and have a problem to create GL 3.0 context with WGL_CONTEXT_PROFILE_MASK_ARB attribute included into attribute list.

marshats
08-21-2009, 06:01 PM
Just a followup on a previous post -- The Freeglut 2.6.0 Release Candidate 1 (http://prdownloads.sourceforge.net/freeglut/freeglut-2.6.0-rc1.tar.gz?download) has a sample (/freeglut-2.6.0/progs/demos/smooth_opengl3/smooth_opengl3.c) showing how to use a single function call glutInitContextVersion (3, 1) to get an opengl 3.1 context and demos a simple shader. This still may be helpful for those who are used to working with glut and want to try and work with the new ogl3 functionality without focusing too much on the wgl\glx boilerplate details.

Aleksandar
08-22-2009, 01:16 AM
Thank you! It is a very useful link for those who start OpenGL programming and do not want to bother with windows management.

But the freeglut cannot solve problems built in drivers, because it is only a wrapper around GL and windows interface APIs. The previous post was just a warning about what might happen if try to use new attributes on the old (3.0) contexts.

Pswin
08-30-2009, 01:55 PM
how can i do MRT in GLSL 150 an OpenGL 3.x?

soconne
08-31-2009, 07:37 AM
[fragment shader]
#version 150

out vec4 out_Color0;
out vec4 out_Color1;

void main()
{
out_Color0 = vec4(0.0, 0.0, 0.0, 0.0);
out_Color1 = vec4(0.0, 0.0, 0.0, 0.0);
}

[C++ code]
// Create and bind shader
glBindFragDataLocation(programID, 0, "out_Color0");
glBindFragDataLocation(programID, 1, "out_Color1");

// Drawing code
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
GLuint buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
glDrawBuffers(2, buffers);

// draw stuff