<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Encelo's Blog &#187; GLX</title>
	<atom:link href="http://encelo.netsons.org/blog/tag/glx/feed/" rel="self" type="application/rss+xml" />
	<link>http://encelo.netsons.org/blog</link>
	<description>When I grow up I want to be a game developer</description>
	<lastBuildDate>Mon, 02 Nov 2009 23:49:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Habemus OpenGL 3.0!</title>
		<link>http://encelo.netsons.org/blog/2009/01/16/habemus-opengl-30/</link>
		<comments>http://encelo.netsons.org/blog/2009/01/16/habemus-opengl-30/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:47:30 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Real-time Graphics]]></category>
		<category><![CDATA[GLX]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[OpenGL3]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=164</guid>
		<description><![CDATA[We have been waiting OpenGL 3.0 for ages, we were all very excited about the wonderful features ARB was promising, then, on the 11th of August 2008, the specs were released&#8230;
I, like everyone else, was really disappointed, the Architecture Review Board was not only really late on schedule but it didn&#8217;t keep its word about [...]]]></description>
			<content:encoded><![CDATA[<p>We have been waiting OpenGL 3.0 for ages, we were all very excited about the wonderful features ARB was promising, then, on the 11th of August 2008, the <a href="http://opengl.org/documentation/specs/">specs</a> were released&#8230;<br />
I, like everyone else, was really disappointed, the <a href="http://www.opengl.org/about/arb/">Architecture Review Board</a> was not only really late on schedule but it didn&#8217;t keep its word about many key features that should have been introduced with this release.<br />
Nevertheless I&#8217;m still confident in the future, when older API functions will be <em>removed</em> and not simply, as in the current version, tagged as deprecated.</p>
<p><img src="http://encelo.netsons.org/blog/wp-content/uploads/2009/01/opengl-3-logo.jpg" alt="OpenGL3 Logo" title="OpenGL3 Logo" width="400" height="118" class="alignnone size-full wp-image-172" /></p>
<p>Now, after the long but needed introduction, let&#8217;s talk about things that matter: today the <a href="http://www.archlinux.org">ArchLinux</a> team moved the new stable 180.22 driver release from the <tt>[testing]</tt> to the <tt>[extra]</tt> repository.<br />
Well, apart from the equally important <a href="http://en.wikipedia.org/wiki/CUDA">CUDA 2.1</a> and <a href="http://en.wikipedia.org/wiki/VDPAU">VDPAU</a> support, this release has been bundled with OpenGL 3 and GLSL 1.30 support, so have a look at how to create an OpenGL 3.0 context.</p>
<p>First of all, it seems like there&#8217;s no other way to open the new context without getting your hands dirty, that is talking directly with GLX.<br />
What follows is a snippet to create an OpenGL 3.0 context integrated in SDL 1.2, which still doesn&#8217;t support it natively.</p>
<p>First of all you need some new defines.</p>
<pre class="brush: cpp;">
#define GLX_CONTEXT_DEBUG_BIT_ARB                         0x00000001
#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB   0x00000002
#define GLX_CONTEXT_MAJOR_VERSION_ARB                  0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB                   0x2092
#define GLX_CONTEXT_FLAGS_ARB                                0x2094
</pre>
<p>You need also to retrieve the address of the following new GLX function.</p>
<pre class="brush: cpp;">
typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC)
	(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB =
	(PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((GLubyte*)&quot;glXCreateContextAttribsARB&quot;);
</pre>
<p>Then you have to define a bunch of GLX related variables.</p>
<pre class="brush: cpp;">
Display *dpy;
GLXDrawable draw, read;
GLXContext ctx, ctx3;
GLXFBConfig *cfg;
int nelements;
int attribs[]= {
	GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
	GLX_CONTEXT_MINOR_VERSION_ARB, 0,
	GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
	0
};
</pre>
<p>At last, after having called <tt>SDL_SetVideoMode()</tt>, create a new context, make it current and destroy the old one.</p>
<pre class="brush: cpp;">
ctx = glXGetCurrentContext();
dpy = glXGetCurrentDisplay();
draw = glXGetCurrentDrawable();
read = glXGetCurrentReadDrawable();
cfg = glXGetFBConfigs(dpy, 0, &amp;nelements);
ctx3 = glXCreateContextAttribsARB(dpy, *cfg, 0, 1, attribs);
glXMakeContextCurrent(dpy, draw, read, ctx3);
glXDestroyContext(dpy, ctx);
</pre>
<p>Don&#8217;t forget to put some querying code, just to be sure the whole process worked. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<pre class="brush: cpp;">
const GLubyte* string;

string = glGetString(GL_VENDOR);
printf(&quot;Vendor: %s\n&quot;, string);
string = glGetString(GL_RENDERER);
printf(&quot;Renderer: %s\n&quot;, string);
string = glGetString(GL_VERSION);
printf(&quot;OpenGL Version: %s\n&quot;, string);
string = glGetString(GL_SHADING_LANGUAGE_VERSION);
printf(&quot;GLSL Version: %s\n\n&quot;, string);
</pre>
<p>On my workstation I get this:<br />
<tt>Vendor: NVIDIA Corporation<br />
Renderer: GeForce 8600 GT/PCI/SSE2<br />
OpenGL Version: 3.0 NVIDIA 180.22<br />
GLSL Version: 1.30 NVIDIA via Cg compiler</tt></p>
<p>If you want to retrieve also the extension list, a new function can help you simplify the process.</p>
<pre class="brush: cpp;">
typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddress((GLubyte*)&quot;glGetStringi&quot;);
</pre>
<p>You can then use it like this:</p>
<pre class="brush: cpp;">
GLint numExtensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &amp;numExtensions);

printf(&quot;Extension list: \n&quot;);
for (int i = 0; i &lt; numExtensions; ++i)
{
	printf(&quot;%s &quot;, glGetStringi(GL_EXTENSIONS, i));
}
printf(&quot;\n&quot;);
</pre>
<p>This new OpenGL version seems to perform just like the old one at the moment, drivers do not honour the <tt>GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB</tt> attribute, this means everything is still in place, backward compatible and unoptimized. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2009/01/16/habemus-opengl-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
