[Kde-games-devel] Ksudoku, Kubrik 3D background
Matthew Woehlke
mw_triad at users.sourceforge.net
Wed Jun 18 02:23:52 CEST 2008
Ian Wadham wrote:
> On Fri, 16 May 2008 02:22 am, Matthew Woehlke wrote:
>> Your pipeline should look like this:
>>
>> - load 2d matrix, viewport coordinates
>> - enable texturing
>> - draw background
>> - [disable texturing; if not being used for the scene]
>> - load 3d [perspective] matrix, scene coordinates
>> - enable lighting, etc
>> - draw scene
>> - disable lighting, etc
>
> Well, I finally sat down to have a go at this yesterday. After a few hours
> fiddling around trying to draw a simple colored rectangle in 2D (even
> switching off all of the 3D graphics in Kubrick), I was unable to get
> anything drawn in 2D to appear on the QGLWidget.
That sounded too much like a challenge to pass up. My 2D GL-fu must
still be good; the attached patch took about 30-40 minutes, of which I
got the background quad rendering in a few minutes and spent most of it
figuring out that I needed the line 'glShadeModel (GL_SMOOTH);' to make
it shade as I wanted. (Say, can we keep this as one of the options? I
like the colors quite a bit ;-).)
The steps aren't quite the same order, but this should give you an idea
what is needed. I'm guessing you missed one of them (I'd be curious
which one).
> Finally I decided to check the Qt doco for QGLWidget, followed the More...
> link and read down to the section headed "Painting Techniques".
I glanced at that briefly... looked like strange stuff. Basically, one
has to understand that "2d" in GL is really just 3d in an ortho
projection. I.e. you're still drawing points, lines, and triangles, and
other primitives must be built from those.
> It says there that it is "possible" to draw 2D graphics onto a QGLWidget
> subclass, but you must reimplement QGLWidget::paintEvent() and use
> QPainter ! Furthermore, the section seems to imply that you can only
> paint on top of the 3D stuff, which is no use for a background. For
> instance, the "Overpainting Example" in the OpenGL example programs
> shows how to paint translucent 2D bubbles in front of a 3D logo.
Ick, that sounds like Ye Olde Tricke of drawing GDI over GL. Nice if you
need a styled combo box, IMO silly otherwise. And of course, it's not
really accelerated as you're mixing drawing methods.
> So I used the following idea, with some of Matthew's mods:
>
> - load a background picture into an OpenGL texture
Needed of course :-).
> - compute a rectangle in 3D that will fill the viewport behind the cubes
Not needed, set your projection right :-).
> - disable lighting
> - enable OpenGL texturing
> - draw the rectangle, applying the OpenGL texture that has the background
> - disable OpenGL texturing
> - enable lighting
> - 3D drawing as usual
...and the rest is the same as my implementation.
> Resizing is blindingly
> fast, if you stay with OpenGL's texture-rendering and do not reload SVG.
..as it should be :-). Sweet.
--
Matthew
I want to vote for a Conservative Democrat. Too bad they're about as
rare as an Honest Politician. Maybe I'll get lucky and someone will come
along that's both.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: background-quick.patch
Url: http://mail.kde.org/pipermail/kde-games-devel/attachments/20080617/de250292/attachment.cc
More information about the kde-games-devel
mailing list