[DEMO] Minimal world engine, updated

I cleaned up a number of issues with the world engine demo.

For now, I worked around the problem with glXChooseVisual sometimes refusing
to set a high resolution depth buffer by changing the shadow demo to use
glPolygonOffset. This is the wrong way to draw shadows anyway; the point of
that demo is really more how to set up a shadow transformation matrix.

Now I don’t specify any gl attributes at all and just let glXChooseVisual
hand me whatever minimal gl configuration it sees fit. This seems to be more
robust, though there is always the possibility that on some platforms
glXChooseVisual will look at all those zero attributes and freak out anyway.
This is issue is by no means resolved, I just avoided it for now.

There’s a new demo world, simple.c, that uses 8 lines of straight-up OpenGL
and 5 lines of glue to define a world containing a single multicolored
triangle. This was originally a demo by Mark Kilgard, comparing OpenGL+Glut
to Direct3D+Directx to see how easy it is to draw something simple. Well,
it’s a lot simpler now.

I’d appreciate some more feedback/complaints about build problems at this
point, and could somebody please try compiling this on Windows, and tell me
how badly my C code breaks VCC.

The source is here:

nl.linux.org/~phillips/world/world.zip

Regards,

Daniel

I cleaned up a number of issues with the world engine demo.

[…]

I’d appreciate some more feedback/complaints about build
problems at this point, and could somebody please try compiling
this on Windows, and tell me how badly my C code breaks VCC.

badly

First some small things that are typical for porting “gcc” SDL
programs to VisualC++. Change the includes from <SDL/SDL.h> to
"SDL.h" and <GL/…> to “SDL_opengl.h”. There are some other header
file differences, such as a missing M_PI (or any kind of pi), and
redefinition of the min and max macros. VisualC++ also does not
permit the usage of “inline” in .c files, nor does it like the LL
suffix (cast to __int64 instead). These are all very small fixes.

The compiler also issues a bunch of warnings: There are about a
hundred places where doubles are truncated (in declarations) or
converted (in expressions) to float, and several signed/unsigned
mismatches.

However, in about 50 places in the code you do this: return
(vec3){x[0], x[1], x[2]}; In other words, you initialize a vec3
object on-the-fly. In VisualC++ this is only allowed when declaring
the variable, like this: vec3 v = { … }; Everywhere else you
should set the struct fields separately, i.e. v.x = …; v.y = …;
etc. I did not feel like fixing all of this, so I gave up. If you
don’t mind changing these on-the-fly initializations to "proper"
declarations, I can give it another shot.

Hope it helps,From: “Daniel Phillips”

Matthijs Hollemans
www.allyoursoftware.com

I’d appreciate some more feedback/complaints about build
problems at this point, and could somebody please try compiling
this on Windows, and tell me how badly my C code breaks VCC.

badly

[…]

However, in about 50 places in the code you do this: return
(vec3){x[0], x[1], x[2]}; In other words, you initialize a vec3
object on-the-fly. In VisualC++ this is only allowed when declaring
the variable, like this: vec3 v = { … }; Everywhere else you
should set the struct fields separately, i.e. v.x = …; v.y = …;
etc. I did not feel like fixing all of this, so I gave up. If you
don’t mind changing these on-the-fly initializations to "proper"
declarations, I can give it another shot.

Hope it helps,

Thanks, it helps a lot. Compound literals are blessed by C99, as you can see
here:

http://wwwold.dkuug.dk/jtc1/sc22/open/n2794/n2794.pdf
(section 6.5.2.5, “Compound Literals”, starting on page 65)

All the rest of the points are minor as you mentioned, and I already fixed
most of them in order to compile the code as c++. However, I rather like my
compound literals, and they are standard, so perhaps the thing to do is to
compile with gcc instead of vcc. Do you have gcc running there?

Regards,

DanielOn Friday 24 January 2003 14:39, you wrote:

From: “Daniel Phillips”

MSVC6 doesn’t support C99 AFAIK, but I believe MSVC7 (.NET) does. FYI.On Fri, 2003-01-24 at 10:42, Daniel Phillips wrote:

http://wwwold.dkuug.dk/jtc1/sc22/open/n2794/n2794.pdf
(section 6.5.2.5, “Compound Literals”, starting on page 65)

All the rest of the points are minor as you mentioned, and I already fixed
most of them in order to compile the code as c++. However, I rather like my
compound literals, and they are standard, so perhaps the thing to do is to
compile with gcc instead of vcc. Do you have gcc running there?

Thanks. I think I’ll drop the other shoe and specify C99 as the minimum
compiler standard for this, not only so I can have compound literals, but
mid-block declarations as well. (There, done.)

For any Debian people, this is all you need to do to change default compiler:

ln -sf /usr/bin/gcc-3.2 /usr/bin/gcc

Or you can just change “cc” in the Makefile to “gcc-3.2”.

Regards,

DanielOn Friday 24 January 2003 18:37, Shawn wrote:

On Fri, 2003-01-24 at 10:42, Daniel Phillips wrote:

http://wwwold.dkuug.dk/jtc1/sc22/open/n2794/n2794.pdf
(section 6.5.2.5, “Compound Literals”, starting on page 65)

All the rest of the points are minor as you mentioned, and I already
fixed most of them in order to compile the code as c++. However, I
rather like my compound literals, and they are standard, so perhaps the
thing to do is to compile with gcc instead of vcc. Do you have gcc
running there?

MSVC6 doesn’t support C99 AFAIK, but I believe MSVC7 (.NET) does. FYI.

For any Debian people, this is all you need to do to change default compiler:

ln -sf /usr/bin/gcc-3.2 /usr/bin/gcc

This is just silly, for Debian people. There’s update-alternatives,
use it.–
Petri Latvala

Normally that would be good advice, except that in this case you want to
update both the cc and gcc links, while /etc/alternatives only points at one
of them (cc). I.e, the default compiler is a bit of a special case, and so
it should be.

Regards,

DanielOn Friday 24 January 2003 22:45, Petri Latvala wrote:

For any Debian people, this is all you need to do to change default
compiler:

ln -sf /usr/bin/gcc-3.2 /usr/bin/gcc

This is just silly, for Debian people. There’s update-alternatives,
use it.