OpenGL: C and D same code - different results

Bill Baxter dnewsgroup at billbaxter.com
Tue Feb 6 06:21:36 PST 2007


dyh wrote:
> recently I've tried few OpenGL examples ported from C to D (on win32)
> and have run into strange problems.
> 
> Translated example was built against same C libs as original, using same
> (translated from platform sdk) headers. Resulted binary is using same dlls
> as original. But there are some differences:
> 
> 1. Behavior
> In original calls glIndexi() has *no* effect. In translation has.
> In original calls glColor3f() has effect. In translation has *not*.
> In original initial color is white. In translation it is kind of brown.
> 
> 2. Performance
> original example performs noticeably faster than translated one.
> 
> No matter what compiler switches I've tried (-O, -inline, -release, etc).
> Example is extremely simple, and i do not see any possibilities to have any
> difference in performance. There is no GC used - there are no memory
> allocations array slice at all. Actually there are no array usage. In fact
> there is nothing at all except opengl api calls. And it is literally same
> library in both example and translation.
> 
> Here is code (~300 lines) 
> original (C) http://paste.dprogramming.com/dpfwrsgw.php
> translation (D) http://paste.dprogramming.com/dpu768pr.php.
> 
> Any tips from opengl experts?

I don't know why, but it seems pretty clear from the results you're 
seeing that the original version didn't actually get the 
PFD_TYPE_COLORINDEX visual it was asking for, whereas the D version 
does.  That would explain the performance difference too because a color 
index visual is probably going to be slow on most modern hardware.

Recent hardware may not even support color index buffers, so it may mean 
you're getting a fallback software renderer in the D case.

Is there some reason why you really need to use a color index visual? 
You'd be much better off with a true color visual.

--bb



More information about the Digitalmars-d mailing list