How to draw polygons with textures and others without


Is it possible to have an object with texturing and plain vertex colours with no texturing added? I have a race car object and I am texturing a number to the side but want the rest of the polygons to use the vertex colours. However as you can see from the picture it just appears all black. The square on the left was a test and uses a texture combined with the vertex colours to produce a coloured texture. Like this in fragement shader:

Texture2D(s_texture, texcoords) * vertex_colour;

This works for the quad, modifying the texture colour but not for plain polygons. So how do you tell openGL to ignore polygons which don’t need a texture applying?? The car object just needs to use the vertex colours for the bodywork and I will add a small (car number) texture to the side. It doesn’t work using my texture shader though as you can see from the picture. The race car object should be coloured using the vertex colours. Adding the Texture2D screws the car up. Hope it makes sense.

EDIT: I suppose the car is screwed up because the texture coordinates are all set to 0.0 for the polygons. But I did this because I don’t want the whole object textured - Just part of it (which I am yet to figure out as its a curved surface). I just want OpenGL to use the computed surface colour.


So you are using shaders? Just supply the shader with a flag that tells it to use the texture or the vertex color. You could just define texcoord 0,0 to mean no texturing:

if (texcoords == vec2(0,0)){
    color = vertexcolor;
} else {
    color = texture( s_texture, texcoords );

Or use an additional vertex attribute for that. Or use 2 draw calls (probably worse than a flag).

Hi menzel. Thanks for the reply. Yes it seems to work even though it seems like a bit of a hack job. :stuck_out_tongue: