Advertisement

question from opengl newcomer

Started by April 13, 2002 04:37 PM
3 comments, last by leggyguy 22 years, 10 months ago
I have been programming in C++ for a few years, but new to opengl. Anyway, I managed to get a box, covered with different textures. Then I decided to add a floor. The floor is just a 1 dimensional quad. But I didn''t use a texture, just a plain green colour. Now if I don''t add this floor, everything works fine, the box is there with the nice textures. But when I add the floor quad and colour it green, then all the other textures in the scene also get a green shade. They are still the correct textures, but green. Anyone know why? The code is something like: void DrawScene () { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef (0.0f, 0.0f, z); glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis By xrot glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis By yrot glBindTexture(GL_TEXTURE_2D, G.texture[0]); //the texture glBegin (GL_QUADS); //drawing of quad goes here, works fine //blah blah glEnd (); //floor glBegin (GL_QUADS); glColor3f(0.0f,0.8f,0.0f);// Set The Color To green glVertex3f(-5.0f, 0.0f, 5.0f); //bot left glVertex3f(5.0f, 0.0f, 5.0f); //bot right glVertex3f(5.0f, 0.0f, -5.0f); //top right glVertex3f(-5.0f, 0.0f, -5.0f); //top left glEnd (); Now if my problem is explained in the tutorial (which are great by the way) at the nehe site I am sorry for missing it. Thanks for help
I''m not an expert on OpenGL - so this could be wrong, but:
I think that the vertex colour from the floor is being carried over into the next frame when you draw your box. So to fix it, you must set the vertex colour to white just before you draw your box.

Hope that helps,

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Advertisement
Thankyou JohnB.

Quite right you are. Probably should have thought of resetting the colour change.

Thanks again. I think I may end up posting quite a bit here, because I am new to the topic. I hope nobody gets mad at my questions.

I spent the last 2 years learning DirectX, and did very well with it, especially DirectPlay and DirectInput, which have been very useful. But Direct3D is a let down, so I am giving OpenGL a try. It will take a while to get to the level I was at with D3D, but everyone tells me it will be worth it.
JohnBSmall is right.

OpenGL is a statemachine. when you set a certain state (e.g. vertex color) it stays in that state until you set it to a new state. It will not forget its state when you''ve rendered a frame of graphics.
--BerLan
quote:
Original post by leggyguy
But Direct3D is a let down, so I am giving OpenGL a try.

What version of DirectX were you using?

I''ve been using Direct3D 8.1, and I''ve found it very easy to get into. But that is (of course) just my-personal-experience (tm) - I know many people find OpenGL easier to work with.

I might start learning OpenGL for real (previously I''ve only done really simple stuff) - I''d be interested to hear what you think of it.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.

This topic is closed to new replies.

Advertisement