Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neonfaktory

OpenGL SIMPLE OpenGL Questions

This topic is 5815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yeah, I know how much people hate that word, but whatever ; I am an OGL n00b@!!# I just want to clear a few things up - should be super simple... Oh, and btw, I''m soo damn tired, please excuse my lack of finesse and general... ugh, i don''t even know what word i wanna use, haha - moving on. My questions: 1. So everything in OpenGL is drawn based on the Camera Position? I think whats tripping me up in this is the "translating" that a keep seeing... When you translate "into" the scene (z going neg, lets say -5.0f), is that simply so you don''t have to keep putting "-5.0f" for the "Z" parameter each time you call "glVertex3f"? 2. Normals... it seems easy enough to create normals for a Cube, but what about wierd angled stuff? Take a Pyramid, for example. WHen you call "glNormal3f", would it require some fancy math to determine the proper normal for those faces? Or maybe I''m missing something..? 3. View Distance - how can I increase it? I know, this is VERY basic stuff, but you gotta start somewhere . Ok, i need sleep - I''m sure I''ll think of some more simple to answer questions... thanks for any help you can provide

Share this post


Link to post
Share on other sites
Advertisement
You got the translate right... it also works for x and y coordinates of course.

You can calculate face normals using the cross product of the three vertices of a polygon. (Two actually). You can read up on that at amir''s 3d site or you coulr read the 3d geomatry primer at flipcode.

Ehm... view distance... Considering you use gluPerpective for setting your view matrix (every time you resize the window for example, and at startup. Nehe''s tutorials use gluPerspective).
gluPerspective(FOV ,Aspect ,near ,far);
The FOV says how "wide" your view is. Usually 45 I think. Aspect is width/height for your window, near is the near clipping plane, and far is the far clipping plane, or the view distance.

I hope this is actually true but I think it pretty well answers your questions.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you haven''t already, read chapter 3 in the Red Book. It has a brilliant explanation of how to manipulate the view matrix in OpenGL.

Share this post


Link to post
Share on other sites
Hey thanks! That''s very helpful Oh, and can I just pick up this Red-Book at any random bookstore, you think? I haven''t heard much about it besides random references.. pardon my not knowing Seems like a big thing in the OpenGL community. THanks again

Share this post


Link to post
Share on other sites
Ok, got a few more questions -

1. I'm not understanding "glRotatef" very well... Now, when you say "glTranslatef" it moves/translates the CAMERA. So when you say "glRotatef", is it rotating the camera? And if it is, how is it determining what point to rotate the camera around? Alot of tutorials i've read make it sound like "glRotatef" is rotating the actual polygons instead of the camera, and if that is the case, I don't understand how it is selecting which polygon to rotate.

2. How does OpenGL handle clipping? Let's say I have a bunch of very small 3D objects in my "world" organized in some sort of list, and a large portion of them probably wont be on the screen at any point in time. Would it be recommended to just tell OGL to draw ALL of them, regardless of position, or would that take a performance hit for some reason as opposed to checking if my objects are actually on screen? And what about a polygon thats half on the screen - does OpenGL handle this stuff automagically?

thanks again

[edited by - neonfaktory on December 7, 2002 3:21:50 PM]

[edited by - neonfaktory on December 7, 2002 3:22:40 PM]

Share this post


Link to post
Share on other sites
The red book can be downloaded somewhere as a pdf, I think gamedev has a copy floating around somewhere.. (Edit: found it )

Other questions..
1. There is no ''camera'' in gl, simply a series of matrix transformations. Moving the ''camera'' forwards is equivilent to moving the entire world backwards. It is simple to do camera style emulation though:


  
// Camera transforms here, but remember they are ''backwards''

gl.translatef(x, y, z);
//...


gl.pushMatrix();
{
// object transforms here, like world position etc.

gl.translate(objX, objY, objZ);
gl.rotatef(objAngle, 0f, 0f, 1f);
renderObject();
}
gl.popMatrix(); // resets to base camera transform


gl.pushMatrix();
{
// rinse, wash, repeat :)

}
gl.popMatrix();


gl.rotatef is always a rotation around the *local* origin. Thus, the order in which you combine rotations and translations is important to get correct results. In above, the obj rotate is on the object coord system, but if the rotate was done in the camera section, it would be affecting the entire world. Push and pop matrix commands let you determin the scope of the various transformations.

2. Clipping will for the most part handle itself - but you''ll probably at some point want to add manual view checking to completly skip the drawing of anything non-visible. Google for view frustum checking for more info. The trick is to do fast clipping on entire objects yourself, and let gl do the per poly stuff for you.

Share this post


Link to post
Share on other sites
Ok, quick question about lighting... I''m using GL_LIGHT0 to do some simple lighting. Now, before I enabled lighting, I made a totally Blue Cube. Now I added some simple Diffuse lighting with LIGHT0, and my Blue Cube is now white... The lighting is definately working, but I lost the color - any suggestions as to why?

Share this post


Link to post
Share on other sites
If you''re setting the blue with glColor*() then it''ll be ignored by default with lighting, instead material properties are used. You''ll need to look into enabling GL_COLOR_MATERIAL and setting it to use the vertex colour for diffuse (and probably ambient).

Share this post


Link to post
Share on other sites
Thanks again Orangy - Another simple question, again about lighting. In general here''s what I''m doing and whats going wrong:

I set up global position array for position of GL_LIGHT0. I then set all the settings and the position for GL_LIGHT0 in my initialization function, enabled it, and it works fine. My beautiful Cube is lit up in blue light .

Next I tried to get the light to move. My plan was to set position to 0,0,0, Push the current matrix, do a "glRotatef(light_angle, 0.0, 1.0, 0.0);" call "glLightfv(GL_LIGHT0, GL_POSITION, Light0_Position);" and then Pop that to get my light to rotate around my cube, BUT... the light doesnt work. If I set GL_LIGHT0''s position AT ALL inside my display function, the Cube appears completely black.

Well, there''s my prob.. It''s probably something dumb I''m doing, but if anyone can help, thatd be great.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!