PDA

View Full Version : Crappy Programming Examples



lucidmm
11-24-2002, 08:38 AM
I have been looking at an NVidia demo for a while: http://developer.nvidia.com/view.asp?IO=Bump_Mapping

I found a few funny things.

1. This function (not written by NVidia) is in tga.c.

int
gliVerbose(int newVerbose)
{
int oldVerbose = verbose;
verbose = newVerbose;
return verbose;
}

I think the above function is a little...
verbose.

2.) The demo is 3000 lines in one file. It's 38 pages when printed out. So you can imagine that it takes some time to piece everything together. My advice is to delete the 7 functions that are never used: doughnut, add_matrices, drawTorusAsPoints, drawTorusAsQuads, FreeTorus, invertMatrix, and transposeMatrix.

3.) You can also delete:
GLUquadricObj *quadObj;
quadObj = gluNewQuadric();
gluQuadricTexture(quadObj, GL_TRUE);

'coz quadObj is never used.

4.) You will probably want to clean up the main function and divide all the other functions into about 3 files.

Other than that, this was a wonderful demo that really showed me how to become a better programmer. It reminds me of my wonderful blind, one-legged ski instructor.

[This message has been edited by lucidmm (edited 11-24-2002).]

knackered
11-24-2002, 08:44 AM
So how much did you pay for this demo?

There's gratitude for you....

lucidmm
11-24-2002, 09:09 AM
Have you ever complained about a stupid commercial, a bad song on the radio, or a horrible TV show?

stefan
11-24-2002, 09:18 AM
One could say that since DX7 we only paid for demos http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

knackered
11-24-2002, 10:55 AM
Originally posted by lucidmm:
Have you ever complained about a stupid commercial, a bad song on the radio, or a horrible TV show?

Yes, because someone will be making money out of those things - but that isn't true here, so silence your protestations.

lucidmm
11-24-2002, 01:01 PM
NVidia is a non-profit corporation?

knackered
11-24-2002, 01:23 PM
No, that's not the point. NVidias demos are part of their developer relations, not a direct play for money. Most of the knowledge imparted by their demos and documents can be applied to most cards, nvidia or non-nvidia.
You have no right to complain, but suggestions are fine.
I'm not one to defend big corporations like nvidia, but your criticisms seem a little churlish.
Complain about such things as nvidia-specific extensions instead of supporting cross-vendor standards, by all means.

Nutty
11-24-2002, 02:01 PM
But dont developer relations employees get paid? So technically, they get paid to produce such work.

And where do they get the money? From ppl buying their graphics cards.

Any why do ppl buy their graphics cards? Cos developers used their features.

And why did developers use their features? Cos the developer relations ppl showed them how. http://www.opengl.org/discussion_boards/ubb/smile.gif

So basically if the dev rel. ppl make the demos nice and easy and clean, then developers will learn, and use their features which in turn makes the public buy nvidia graphics cards, which in turn pays the dev rel ppl http://www.opengl.org/discussion_boards/ubb/smile.gif

Nutty

cass
11-24-2002, 02:33 PM
Just to clarify - you'd be right to complain if NVIDIA didn't support a cross-vendor exension while supporting its own vendor-specific version.

NVIDIA will expose all our hardare's capabilities through extensions. We favor cross-vendor extensions where available, but we use vendor-specific extensions as necessary.

Vendor-specific extensions are not a bad thing. They are how we prove the usefulness of extending OpenGL in a specific away.

NV_vertex_program begat ARB_vertex_program which begat ARB_fragment_program. That's a Good Thing.

Thanks -
Cass

PS Edited stupid spelling error.


[This message has been edited by cass (edited 11-24-2002).]

jwatte
11-24-2002, 04:40 PM
I'd hope that nVIDIA's job is to teach you how to use their hardware, assuming you're already a good programmer. It's some college or professional school's job to make you a good programmer. Well, that, plus a year of actually doing it with people who have done it before :-)

When I go through a demo or try to dive into any code, I use Find/FindInFiles a lot, and I usually start at main() and trace through the program to figure out what it's doing. That means I only get to read the parts I care about, and it doesn't really matter if the program puts each function in its own file (horror!) or puts all functions in one file (horror!).

V-man
11-24-2002, 06:43 PM
Their examples are long and complex looking, but a good number of them (all) are easy to understand.

Do you know what the trick is? Dont look at the irrelevent parts of the code. Who cares what's in the tga or png loading file. Who cares how they are loading their models. Who cares how they loading extensions.

All those programs have a main, diplay, init, mousemove, mouseclick, keyboard, ... functions

init, display, keyboard are the core of those demoes. So use your Find function often.

PS: thanks to the software rasterizer, you wont be forced to upgrade if you're short on money and are dying to run those next generation extensions. Is Nvidia nice or what?

V-man

dorbie
11-24-2002, 06:49 PM
Those developers are too busy getting on with the next demo to worry about assing around to eliminate 4 lines of code here or there. They'd rather spend the time writing another 1000 lines in their next demo. Keep it in perspective. What would you rather have, anal-retentive code or more examples of the next cool thing?

P.S. this is a good example of how you should write code if you want to be productive. Grab a library from here or there and use it. Don't worry about the unimportant details and don't even look at the code if it works and you can trust it.


[This message has been edited by dorbie (edited 11-24-2002).]

lucidmm
11-25-2002, 03:58 AM
I'm not complaining about NVidia extensions. I think NVidia is a awesome company that is a key player in the world of computer graphics. I will learn and have learned a tremendous amount from their website. I will continue to buy NVidia cards.

With that having been said, the programming style in the bump mapping demo is horrid. It looks like Spaghetti Code-And-Fix to me. But who knows, maybe I'm just a crappy programmer.

I hope that the NVidia Developer Relations does not mean, "We put a some code on a website. But don't tell us what you think about it."

Here are two final questions:

Why is the demo in one 3000 line file with seven unused functions?

Does anyone at NVidia care that programmers have a hard time figuring out how their demos work?

dorbie
11-25-2002, 04:31 AM
You show a couple of simple and easily understood pieces of code that are completely unambiguous, one is even designed to clarify readability and you complain about spaghetti code. It sounds like you don't have a clue what real spaghetti code is.

Some code is necessarily complex because it does difficult things.


[This message has been edited by dorbie (edited 11-25-2002).]

knackered
11-25-2002, 04:50 AM
Nutty: and just how are you related to Kevin Bacon? ( http://www.cs.virginia.edu/oracle/ )

lucidmm: To be honest, I'm not even sure if that bump mapping demo is meant as a "programming-bumpmapping" teaching aid, I would say it's more of an interactive presentation of perpixel lighting, meant to be watched rather than disected - so try not to be too harsh...ever been up against a deadline? Noticed how your coding gets uglier and uglier the nearer to crunch time you get? I imagine that was the case before they presented it at some show or other....

lucidmm
11-25-2002, 05:28 AM
I have no idea what you are talking about Dorbie. Please be more specific.

If the demo was written as just a demo to show off NVidia capabilities, then I would like to hear that. All of you have been talking about deadlines, but it has been proven that Code-And-Fix takes MORE time.

I am all for code re-usability, but the way to reuse code is to encapsulate all common code into the one file. Cutting and pasting individual functions is a mistake.

The way I see it bumpdemo.c should have been split up like this:

main.c (glut stuff)
bumpMapTextures.c (normal maps and textures)
combiners.c (set up register combiners and check for extensions)
matrix.c (matrix operations)
torus.c (rendering a bump-mapped torus)

bumpMapTextures.c, combiners.c and matrix.c would all be highly reuseable.

If this code wasn't on NVidia's site, I'm sure many of you would see it for what it is.

knackered
11-25-2002, 06:43 AM
Have you actually programmed in a commercial environment, lucidmm?

dorbie
11-25-2002, 06:50 AM
I was referring to your post that started this thread.

If you want code structured the way you like online how about providing it. There's nobody stopping you.

When you've done as much as NVIDIA to offer free code and training maybe I'll rate your complaints.

Nutty
11-25-2002, 07:46 AM
Nutty: and just how are you related to Kevin Bacon? ( http://www.cs.virginia.edu/oracle/ )

eh ?!

Mark Kilgard
11-25-2002, 10:24 PM
Wow, an entire thread devoted to what a crappy programmer I am. I don't know what to say.

Sure, bumpdemo.c could have been divided up into more than, say, one source file. Sure, there's some dead code sprinkled here and there (think: bonus code). But neither is the worst failing of bumpdemo.c...

Why has no one mentioned the biggest failing of bumpdemo.c -- that it only bump maps tori (and only one at that)?

That's great if you want to write Sim Krispy Kreme or Bagel-mania 3D, but a bump mapping demo that just bump maps a torus is pretty lame if you ask me.

- Mark

John Pollard
11-25-2002, 11:17 PM
Originally posted by Mark Kilgard:
Wow, an entire thread devoted to what a crappy programmer I am. I don't know what to say.

Sure, bumpdemo.c could have been divided up into more than, say, one source file. Sure, there's some dead code sprinkled here and there (think: bonus code). But neither is the worst failing of bumpdemo.c...

Why has no one mentioned the biggest failing of bumpdemo.c -- that it only bump maps tori (and only one at that)?

That's great if you want to write Sim Krispy Kreme or Bagel-mania 3D, but a bump mapping demo that just bump maps a torus is pretty lame if you ask me.

- Mark

Mmm, Krispy Kreme. Reminds me, I'm visiting family in Oklahoma for thanksgiving, and they have a Krispy Kreme plant right there in town, which makes them right in front of you. Can't wait!

-John



[This message has been edited by John Pollard (edited 11-26-2002).]

knackered
11-26-2002, 01:50 AM
Originally posted by Mark Kilgard:
Wow, an entire thread devoted to what a crappy programmer I am. I don't know what to say.

Sure, bumpdemo.c could have been divided up into more than, say, one source file. Sure, there's some dead code sprinkled here and there (think: bonus code). But neither is the worst failing of bumpdemo.c...

Why has no one mentioned the biggest failing of bumpdemo.c -- that it only bump maps tori (and only one at that)?

That's great if you want to write Sim Krispy Kreme or Bagel-mania 3D, but a bump mapping demo that just bump maps a torus is pretty lame if you ask me.

- Mark

Only if you're trying to teach how to calculate the tangent space vectors....I found it annoying that they were just derived from the torus equation. You should have generated the torus mesh, then extracted the tangent space vectors from that arbitary mesh.
Other than that, I thought it was a pretty cool demo.

lucidmm
11-26-2002, 04:16 AM
Originally posted by Mark Kilgard:
Wow, an entire thread devoted to what a crappy programmer I am. I don't know what to say.

Sure, bumpdemo.c could have been divided up into more than, say, one source file. Sure, there's some dead code sprinkled here and there (think: bonus code). But neither is the worst failing of bumpdemo.c...

Why has no one mentioned the biggest failing of bumpdemo.c -- that it only bump maps tori (and only one at that)?

That's great if you want to write Sim Krispy Kreme or Bagel-mania 3D, but a bump mapping demo that just bump maps a torus is pretty lame if you ask me.

- Mark

You are by no means a crappy programmer. Any graphics book usually has 4 or 5 references to your work. You've taught me more than my professors. The paper "A Practical and Robust Bump-mapping Technique for Today's GPUs" is brilliant. It is complete and well organized. It covers both theory and implementation. The appendices contain all the relevant bump mapping functions. There is no "bonus code" in the paper.

I am sorry that I offended, but it is frustrating and difficult for a novice like me to understand what is happening in bumpdemo.c. But I'll keep trying because I think it's a pretty cool demo too.

Thanks.

Robbo
11-26-2002, 07:35 AM
Please lucid, this board is supposed to be ayass kissing free -

By the way Mark - can you send me a signed photo? Its for my kid-sister you understand.....

zed
11-26-2002, 07:39 AM
>>That's great if you want to write Sim Krispy Kreme or Bagel-mania 3D, but a bump mapping demo that just bump maps a torus is pretty lame if you ask me.
- Mark<<

i was to personally disappointed to see your standards are dropping mark, where were the comments like
'i have to stick this in cause of the stupidy of windows' etc

lucidmm
11-26-2002, 08:13 AM
Originally posted by Robbo:

Please lucid, this board is supposed to be ayass kissing free -

By the way Mark - can you send me a signed photo? Its for my kid-sister you understand.....

lol! So I can't be critical, but I can't kiss his ass either? I guess I need to find some middle ground.

Korval
11-26-2002, 10:14 AM
You should have generated the torus mesh, then extracted the tangent space vectors from that arbitary mesh.

Actually, I disagree. If you actually have a mathematical equation that represents a mesh (or one you used to generate that mesh), then you should use that to generate your normals/tangents/binormals. After all, the vertices themselves are at the position on the mathematical function. You'll get better lighting with normals based on the mathematical function, rather than deriving them from the mesh.

knackered
11-26-2002, 12:13 PM
But that's no use if you want to learn about bump mapping geometry - I've never had cause to generate my geometry from mathematical functions. http://www.opengl.org/discussion_boards/ubb/wink.gif
So it was wrong not to demonstrate deriving tangent space from arbitary geometry in a bump mapping demo, in my opinion.

davepermen
11-26-2002, 12:16 PM
the demo was about the how to do bumpmapping. not how to set up a mesh for bumpmapping http://www.opengl.org/discussion_boards/ubb/biggrin.gif
today most of us do that with tools anyways, if developing bigger projects. so they don't need to know that anymore http://www.opengl.org/discussion_boards/ubb/biggrin.gif

cass
11-26-2002, 04:11 PM
If nothing else, this thread was a success because it got Mark to post. http://www.opengl.org/discussion_boards/ubb/smile.gif

We'll see how long it takes for a second post.

Cass

Gorg
11-26-2002, 04:40 PM
Originally posted by cass:

If nothing else, this thread was a success because it got Mark to post. http://www.opengl.org/discussion_boards/ubb/smile.gif

We'll see how long it takes for a second post.

Cass

Well. let's get to work.

Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark! Mark!

martin_marinov
11-26-2002, 04:41 PM
Hi,

I think I agree with Korval. If one has analytical way to derive _exact_ tangents, these are the best which you can use for any application. Approximating tangents from an arbitrary mesh geometry by using even relatively good ways like Taubin's method, quadratics fitting or subdivision approximation still lack robustness in cases where the mesh is coarse or non-uniform sampled and generally depends on the tessellation.
If your models is tessellation of NURBS surfaces or subdivision/multiresolution surfaces (like most meshes produced by modeling programs) or has any other analytical representation, you have exact ways to compute tangents/normals and it is best to use them.

Regards
Martin

rgpc
11-26-2002, 06:08 PM
Originally posted by zed:
i was to personally disappointed to see your standards are dropping mark, where were the comments like
'i have to stick this in cause of the stupidy of windows' etc

Maybe Marks working on the cg/HLSL compatibility project and doesn't want to upset MS? I mean it'd be a shame if the following found it's way into the next Win Service pack...

if (GL_VENDOR == 'nVidia')
{
if (MS->User.PayMS(GL_MORE))
MS->User.FobOff();
else
WinXP->MSSupport = false;
WinXP->FatalException();
}

http://www.opengl.org/discussion_boards/ubb/wink.gif

[This message has been edited by rgpc (edited 11-26-2002).]

knackered
11-27-2002, 03:27 AM
Originally posted by davepermen:
the demo was about the how to do bumpmapping. not how to set up a mesh for bumpmapping http://www.opengl.org/discussion_boards/ubb/biggrin.gif
today most of us do that with tools anyways, if developing bigger projects. so they don't need to know that anymore http://www.opengl.org/discussion_boards/ubb/biggrin.gif

You are insane, Dave.

PH
11-27-2002, 03:46 AM
Originally posted by cass:

If nothing else, this thread was a success because it got Mark to post. http://www.opengl.org/discussion_boards/ubb/smile.gif

We'll see how long it takes for a second post.

Cass

I never thought that he even read the posts here, did you mention the thread http://www.opengl.org/discussion_boards/ubb/smile.gif ? It's kind of like with Simon Green...I'm always surprised when I he posts.

Diapolo
11-27-2002, 03:53 AM
Originally posted by cass:

If nothing else, this thread was a success because it got Mark to post. http://www.opengl.org/discussion_boards/ubb/smile.gif

We'll see how long it takes for a second post.

Cass

Nice work, thanks Cass http://www.opengl.org/discussion_boards/ubb/smile.gif.

Now if only John Carmack would post here too http://www.opengl.org/discussion_boards/ubb/biggrin.gif.

But for now ... Go Mark, GO http://www.opengl.org/discussion_boards/ubb/wink.gif!

Diapolo

btw.: I saw that one from 3D Realms posted here, too. When will we see Duke 4 Ever *g*?

John Jenkins
11-27-2002, 04:17 AM
I love chocolate

[This message has been edited by John Jenkins (edited 11-27-2002).]

Ysaneya
11-27-2002, 05:14 AM
I smell flames. Must re..ss...is...t.

davepermen
11-27-2002, 07:55 AM
Originally posted by knackered:
You are insane, Dave.

what? i am not insane, not crazy. just.. hm lets forget this http://www.opengl.org/discussion_boards/ubb/biggrin.gif

but my statement was true http://www.opengl.org/discussion_boards/ubb/biggrin.gif

knackered
11-27-2002, 10:10 AM
You are insane to seperate out calculating tangent space and performing perpixel lighting - what else do you use tangent space for?
You're just being contrary for the sake of it.

zeckensack
11-27-2002, 10:13 AM
And he's been grinning quite a lot lately ...

davepermen
11-27-2002, 10:40 AM
Originally posted by knackered:
You are insane to seperate out calculating tangent space and performing perpixel lighting - what else do you use tangent space for?
You're just being contrary for the sake of it.

what? at least i don't need to generate tangent space on models anymore. as i said, for this, tools are there..

http://www.opengl.org/discussion_boards/ubb/biggrin.gif and yes i am insane, i know it.

and yes, if there is something to contradict, i always have to note it..
you just don't get anymore where sarkasm is in the play, do you?

you do..

so i messed it up?

oh well..

anyways, i loved your demo, matt, and with the .ppt docs and so (the ones with your app in pictures in), i learned quite much..

still.. code would be nice to be shorter..

at least its much bether than the todays nveffectsbrowser/cgbrowser constructs wich can't exist without complicated huge downloads and installations anymore.. bether one simple app with one simple .cpp file (or .c) wich is simply huge, than complicated stuff like those "ide"s to download, with sourcetrees, installations and all.. bah.. who needs that?

and i'm for the exact tangent space derivation if you have it. go for it, matt http://www.opengl.org/discussion_boards/ubb/biggrin.gif

(do we get a second post from him? http://www.opengl.org/discussion_boards/ubb/biggrin.gif)

zeckensack
11-27-2002, 11:36 AM
His name's Mark. Matt is someone else.

Humus
11-27-2002, 12:18 PM
Originally posted by PH:
I never thought that he even read the posts here, did you mention the thread http://www.opengl.org/discussion_boards/ubb/smile.gif ? It's kind of like with Simon Green...I'm always surprised when I he posts.

I would assume he reads it regularly. I once received an email from him after (wrongly) complaining about nVidia at this forum.

davepermen
11-27-2002, 12:21 PM
sorry its mark. matt. mark.. ah i simply _CANT_ remember names.. http://www.opengl.org/discussion_boards/ubb/biggrin.gif

sorry for that.

GPSnoopy
11-27-2002, 12:49 PM
IMO NVIDIA could be a little more careful with the code they release.
It can scale from weird coding style to a monstruous pile of bugs.

Cleaner and more understandable code/examples can only be more beneficial to developers.

M/\dm/\n
11-28-2002, 03:12 AM
Sometimes demos aren't very easy to understand, especialy for beginners "mmender.objectrender->vertexarray.get(sizes->...", and as far as I know from my own experience they aren't quicker and bugless. From my point of view I'm only positive about GLUT, because all custom calls makes find function your best friend http://www.opengl.org/discussion_boards/ubb/frown.gif. Even helios engine hides too much http://www.opengl.org/discussion_boards/ubb/frown.gif

Talking about BUGZ, cant wait for NV30. I just wanna hang it with infinite repeat http://www.opengl.org/discussion_boards/ubb/eek.gif