PDA

View Full Version : textured <-> vertex only



mikethebike
11-28-2011, 02:31 AM
Hi
why does the first draw the texture but the second vertex only code not?
Thanks Michael


glBegin(GL_QUADS);
glTexCoord2f(1, 1.0f); glVertex2f(right, bottom); // Bottom Right Of The Texture and Quad
glTexCoord2f(0, 1.0f); glVertex2f(left, bottom); // Bottom Left Of The Texture and Quad
glTexCoord2f(0, 0.0f); glVertex2f(left, top); // Top Left Of The Texture and Quad
glTexCoord2f(1, 0.0f); glVertex2f(right, top); // Top Right Of The Texture and Quad
glEnd();

---------------

glBegin(GL_TRIANGLES);
glColor4f(0.0, 0.0, 1.0, 1); /* blue */
glVertex2f(right, bottom);
glColor4f(0.0, 1.0, 0.0, 1); /* green */
glVertex2f(left, bottom);
glColor4f(1.0, 0.0, 0.0, 1); /* red */
glVertex2f(left, top);
// glColor4f(1.0, 0.0, 1.0, 1); /* ? */
// glVertex2f(right, top);
glEnd();

tksuoran
11-28-2011, 03:02 AM
The second code does not specify per vertex texture coordinates. Thus "current texcoord" value is used for all vertices. When texcoord is same for all vertices, it is constant across the whole primitive, and you will only get a constant color from the texture, assuming you still have texturing enabled.

mikethebike
11-28-2011, 03:20 AM
Thanks but that changes nothing or how should below look?

glBegin(GL_TRIANGLES);
glColor4f(0.0, 0.0, 1.0, 1); /* blue */
glTexCoord2f(1, 1.0f);
glVertex2f(right, bottom);
glColor4f(0.0, 1.0, 0.0, 1); /* green */
glTexCoord2f(0, 1.0f);
glVertex2f(left, bottom);
glColor4f(1.0, 0.0, 0.0, 1); /* red */
glTexCoord2f(0, 0.0f);
glVertex2f(left, top);
glEnd();

basically I want to draw something alike:
http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html
simple.c...very simple indeed...

BionicBytes
11-28-2011, 04:47 AM
basically I want to draw something alike:
http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html

None of those images use textures. Therefore supplying texture coorinates and a texture will mean OpenGL uses a texture and applies it to the vertex data (aka texture mapping).

going back to your first post


why does the first draw the texture but the second vertex only code not?
You seem to have changed your mind! Your own second example sends only colours and vertex data to GL - and that's what you want to do to create those screen shots.

mikethebike
11-30-2011, 02:52 AM
Again see my first question. textured is drawn but not in colors only. WHY? I've tried different glBlendFunc without success. This is a dll so maybe the parent does some weird things? vertex only is transparent...nothing visible at all.

tksuoran
11-30-2011, 03:19 AM
Are you saying that the second code does not render anything (visible) at all?

What (colors) do you have in the framebuffer before the code?
Do you still have texturing enabled? What colors you have in the texture? For example, rendering black textured triangle on black background will not have a visible effect.

mikethebike
11-30-2011, 03:27 AM
tried all kind except below everything is white not transparent
glClear(GL_COLOR_BUFFER_BIT);

the parent draws some textures and the region i draw is like cut out his textures to see behind. Fully transparent execpt white when using as above.
but i can draw also textures but not colors.

tksuoran
11-30-2011, 03:31 AM
And are you sure you have texturing disabled? glDisable(GL_TEXTURE_2D)

mikethebike
11-30-2011, 04:20 AM
Cool! Many thanks