|
This thread is locked; no one can reply to it. |
1
2
|
AllegroGL Tricks... |
Michael Jensen
Member #2,870
October 2002
|
So, OpenGL is forcing me to draw farther objects away first, and closer objects last -- silly me, but then why do I have/need a 3D card if I have to do all of this in software anyway? -- am I missing something? maybe there's a mode I can set or something? ~sigh~ {"name":"590862","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/5\/c589fc810fee2c07d338dc0d49672f7c.jpg","w":640,"h":480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/5\/c589fc810fee2c07d338dc0d49672f7c"} this is my set video mode function that I cannibalized from like three different tutorials:
Can anyone point me in the right direction?
|
GullRaDriel
Member #3,861
September 2003
|
I think you should do some searching on something called zbuffer. If I remember correctly, with opengl you can do some sort of 'scenes' of objects, which are automagically sorted by the graphic card. But beginning by reading some stuff on ZBuffering is a good thing. I already have done a software zbuffering system, so I can explain you how it works, even if I think that opengl will do this lonesome. "Code is like shit - it only smells if it is not yours" |
X-G
Member #856
December 2000
|
glEnable(GL_DEPTH_TEST); -- |
Michael Jensen
Member #2,870
October 2002
|
BADASS! [edit]
|
GullRaDriel
Member #3,861
September 2003
|
Huh ? why ? He gaves you the right answer you know, and with some little more search you will have found it too :p EDIT: review your google skills http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/depthmask.html _ "Code is like shit - it only smells if it is not yours" |
Michael Jensen
Member #2,870
October 2002
|
"badass." == "wow, neat." == "damn cool." -- it's a compliment, er, sort of. edit:
|
GullRaDriel
Member #3,861
September 2003
|
Damn ! Sorry for misunderstooding you . Your second question have been answered too. Opengl link given before said:
NAME C SPECIFICATION PARAMETERS DESCRIPTION ERRORS ASSOCIATED GETS SEE ALSO _ "Code is like shit - it only smells if it is not yours" |
Michael Jensen
Member #2,870
October 2002
|
thank you much.
|
Billybob
Member #3,136
January 2003
|
Zbuffers are fun ... until you deal with translucency.
|
kikabo
Member #3,679
July 2003
|
yeh, because of translucent glitches I added object sorting quite late in a project which was a bit of a pain at a late stage. If you are going to add transluceny objects it might be worth considering sorting sooner rather than later. ed: translucent objects including perhaps bill board sprites for explosions, glow effects on anything or shadows. |
Jonatan Hedborg
Member #4,886
July 2004
|
How is the normal way of solving that again? Something like that?
|
Thomas Harte
Member #33
April 2000
|
Quote:
1. Draw all solid objects, unsorted but with Zbuffer on (read/write) Something like that? I'm not sure why you'd want to set the z-buffer to read only, but I normally divide all my objects into a transparent and an opaque part at startup then, per frame:
Drawing opaques from front to back is a good idea because graphics cards are very good now at throwing away large chunks of polygon if they're invisible without doing any perpixel work. Especially if you're sorting your objects anyway, you might as well do it this way. For dealing with transparency within an object I usually either BSP that part of it or ignore the problem and make a note not to use any complicated transparent sections! [My site] [Tetrominoes] |
Mika Halttunen
Member #760
November 2000
|
Jonatan Hedborg
Member #4,886
July 2004
|
Quote: Drawing opaques from front to back is a good idea because graphics cards are very good now at throwing away large chunks of polygon if they're invisible without doing any perpixel work. Especially if you're sorting your objects anyway, you might as well do it this way.
Hmm. I'm not sure if it's overall more effective to just sort the transparent triangles/groups or all of them (but in different order) - Depends on where the bottle-neck is, i suppose (GPU power vs. CPU power). I think the read-only ZBuffer is because a rough sort may have errors, so rather than not drawing the "faulty" polygons (because they are behind something else), we draw them at the "slightly wrong place" instead (but with faulty blending, probably).
|
Michael Jensen
Member #2,870
October 2002
|
Holy Cow -- I just spent the whole day figuring out how to get some sort of lighting to work, fog was pretty easy though -- but it sounds like there are a LOT of caveats/things that don't "just work" when using OpenGL -- is there a guide somewhere? This is a bitch.
|
X-G
Member #856
December 2000
|
Eh, there are tutorials, and reference docs. It really isn't that hard OR quirky; most is pretty straightforward if you know what you're doing. What's the problem? -- |
Michael Jensen
Member #2,870
October 2002
|
Eh, for the moment: For a long time I couldn't figure out how to use fonts -- finally I just gave up and used "allegro_gl_set_allegro_mode();" and "allegro_gl_unset_allegro_mode();" and used the allegro routines to draw on the screen, which is a nice feature I guess -- does this hurt the fps at all? I don't notice a difference on my box -- but that's just my box -- also when I save screen to a .bmp file, it comes out upside down, and seems to take forever! I really can't find anything on beginner level on lighting -- other than I'm supposed to pass a "normal" into glNormal3f, (I understand that x, y, and z have to be between 0, and 1, but what does this value indicate -- is it the direction the light is shining from it's source? I'm not quite sure... found all kinds of strange math that made no sense for lighting :-( finally got lighting working with float Shiney[] = { 127.0 }; glMaterialfv(GL_FRONT, GL_DIFFUSE, color); glMaterialfv(GL_FRONT, GL_SPECULAR, grey); glMaterialfv(GL_FRONT, GL_SHININESS, Shiney); where color is the color of my rectangle/triangle. BUT -- the lighting isn't constant like real world lighting -- it moves around with the camera moving around -- maybe I'm transforming wrong? -- Really I have no idea what I'm doing and the tutorials seem to all end right after the basics, or they get really heavy into math without explaining the math or giving references to something that does. :-( [/whine]
|
Jonatan Hedborg
Member #4,886
July 2004
|
A normal is the direction that the surface in question is "pointing". If the light moves around with the camera you are probably setting it's position at the wrong place. You should set it after you set your camera i think (before drawing polygons).
|
Thomas Harte
Member #33
April 2000
|
Quote: I really can't find anything on beginner level on lighting -- other than I'm supposed to pass a "normal" into glNormal3f, (I understand that x, y, and z have to be between 0, and 1, but what does this value indicate -- is it the direction the light is shining from it's source? I'm not quite sure... The normal is a vector pointing at a right angle to the surface it is on. For example, when you're walking along a perfectly flat surface the vector from your feet to your head is the surface normal for the floor. If you throw a dart into a dartboard then usually the vector running along the dart is pretty close to the surface normal for the dartboard. The complicated maths you've seen probably uses the cross product. The cross product takes two vectors and produces a third that is at a right angle to the first two. If the first two vectors both lie on a particular surface then that means that the vector it produces is at a right angle to the surface — so it is the normal. The code tends to look a bit more confusing than it needs to be because you first have to get two vectors on the surface, which is normally done by just subtracting the position of some vertices from some others. Also, it isn't that all the components of the normal should be unit length, it's that the entire vector should be unit length. So if you measured the actual vector you'd find out it was length 1. You can ensure that yourself using Pythagoras and sqrt, or let OpenGL do it for you (with glEnable(GL_NORMALIZE)). If there's no way of doing it advance you might as well let OpenGL do it, if you can do it in advance then you should. Quote: BUT -- the lighting isn't constant like real world lighting -- it moves around with the camera moving around -- maybe I'm transforming wrong? You need to set the light position (with glLightfv(GL_LIGHT_POSITION), it doesn't matter if you're only using a directional light and never forget that the vector you pass is four dimensional!) after you've set up the world camera, because it is transformed by MODELVIEW. So your code is probably something like:
[My site] [Tetrominoes] |
X-G
Member #856
December 2000
|
Harte is correct, and I remember this is something that tends to throw beginners off: GL_LIGHT_POSITION is transformed by the current modelview matrix! Also, it's important to note, if you are using point lights, that the w coordinate must be set to 1. The light "position" is a homogeneous coordinate, with 1 being appropriate for points, and 0 for directions; it's not sufficient to only pass three floats to glLightfv! If you show us more code, we can help more. -- |
Michael Jensen
Member #2,870
October 2002
|
so then I should set the light position every frame... that will probably work. I noticed that it took 4 parameters, and that the fourth one was always a 1 or 0 in examples I saw -- according to X-G I should pass in 1 if it's a point, and 0 if it's a direction for the last parameter? Which surface should I pass in the normal for? In all of the example programs I've seen, glNormal3f is only called once per loop (usually with constant values) -- but if I have 100 polygons, each with their own normals which normal do I pass in? or do I pass it in for every polygon?
|
X-G
Member #856
December 2000
|
Quote: or do I pass it in for every polygon? That. -- |
Michael Jensen
Member #2,870
October 2002
|
Ok, well I moved the lighting position to be called once per frame, and the lighting stopped moving around -- badass! Also, I have this function:
I have no idea how it works, but it's supposed to return a normal (I stole it from a tutorial) of any polygon I pass in so long as I pass in 3 of it's points in counter clockwise order, so I guess I'll start doing that.... and making a call to glNormal3f for every polygon I render -- I translate/rotate the polygons -- do the points I pass in to glNormal3f get translated/rotated with them? Only confusing thing is -- I can't seem to find any programs/etc (even the tutorial) that call glNormal3f more than once per draw loop -- if you're supposed to pass it in for every polygon why is everyone cheating!? -- that's what makes it confusing... Edit: Neat, it's all working -- but I get horribly exagerated results -- the bright areas are too bright and the dark areas are too dark -- I moved the light farther away and to an angle, and now I just have the problem of the dark areas being too dark... it would be nice if they just went to a darker shade of the same color rather than pure grey....
|
X-G
Member #856
December 2000
|
They are probably doing that to make the tutorials simpler for you. Remember that OpenGL is a state machine; if the normals don't change between each vertex fed to the hardware, it'll just keep using the same one. The right thing to do is have one normal per face (actually, one per vertex). (Also, precalculate the normal. Don't do it every frame.) As for the light, check into ambient settings, reduce your specular component, and possibly add attenuation. -- |
Michael Jensen
Member #2,870
October 2002
|
Thank you X-G -- Also, can you recomend a good OpenGL Book? -- It just hit me that I should probably buy a book.
|
|
1
2
|