I have a program that is to be capable of several things, first, if I hit a button multiple times it will toggle between multiple modes.

Right now though while I can toggle between either a wireframe or a solid I can't have both. I know conceptually the solution is to have "two" objects, one wiremesh and one a solid and then use gloffset etc etc etc.

Right now I just want to see if there's a way, ANY way at all, to do both wiremesh+solid.

Thanks.

tonyo_au

02-05-2014, 04:09 PM

If you want to display a wireframe on top of a solid render without using a geometry shader you will need to do several passes to avoid z-buffer fighting.

You could try the following steps

1) enable the stencil buffer, disable the colour buffer and render the wireframe

2) disable the stencil buffer

3) clear the depth buffer but not the stencil buffer

4) render the solid geometry

5) enable the stencil buffer, disable the depth buffer and render a whole screen quad to show the wireframe

Note that this will show the back faces in wireframe not just outline the front faces

nenad*

02-05-2014, 05:01 PM

What do you get on screen when you run posted code?

RaenirSalazar

02-06-2014, 11:02 AM

Uh, the forum doesn't seem to let me post urls so, yeah.

I *think* I got some sort of mesh after running the code, but I also can't seem to change the color at all.

If you want to display a wireframe on top of a solid render without using a geometry shader you will need to do several passes to avoid z-buffer fighting.

You could try the following steps

1) enable the stencil buffer, disable the colour buffer and render the wireframe

2) disable the stencil buffer

3) clear the depth buffer but not the stencil buffer

4) render the solid geometry

5) enable the stencil buffer, disable the depth buffer and render a whole screen quad to show the wireframe

Note that this will show the back faces in wireframe not just outline the front faces

I kinda already have the problem of where the code that *should* have worked doesn't for reasons I do not understand, can you be more specific syntaxwise?

Brokenmind

02-06-2014, 12:03 PM

I remember having done this a while ago, and I have some questions to your code above:

First, you fill the polygons with glPolygonOffset, and after that, you draw the lines without glPolygonOffset. To my mind, it should be done the other way around: Fill faces without the offset, and draw the lines "on top of" the filled faces (therefore the offset. 1.0 as both parameters should do).

Maybe it could help to move the drawing code to a sub-routine to make it more readable and maybe find your error by that. By the way, what "does not work" with your code? Do you see anything or can't you get the syntax right?

As for the third code box: What does setFlagCtr do? Maybe you should just set two bools for both filled and wireframe display so that you can decide to draw them separate from each other. Drawing both is not definable in the glPolygonMode, as you already mentioned ;)

Edit: glClearColor(1, 1, 1, 0) won't work, you can't clear with a transparent color (the last value should always be 1)

RaenirSalazar

02-06-2014, 12:13 PM

I remember having done this a while ago, and I have some questions to your code above:

First, you fill the polygons with glPolygonOffset, and after that, you draw the lines without glPolygonOffset. To my mind, it should be done the other way around: Fill faces without the offset, and draw the lines "on top of" the filled faces (therefore the offset. 1.0 as both parameters should do).

Maybe it could help to move the drawing code to a sub-routine to make it more readable and maybe find your error by that. By the way, what "does not work" with your code? Do you see anything or can't you get the syntax right?

As for the third code box: What does setFlagCtr do? Maybe you should just set two bools for both filled and wireframe display so that you can decide to draw them separate from each other. Drawing both is not definable in the glPolygonMode, as you already mentioned ;)

So the problem it turns out is since we were operating using code provided by the professor (which as it isn't an Opengl class but a computer graphics class that happens to use opengl and thus aren't taught opengl) it had some funny business going on that I still don't quite understand but it comes down to being unable to switch color using opengl commands.

I had to use glEnable(GL_COLOR_MATERIAL); (the opengl superbible I have doesn't mention this for its beginner applications, anyone know why this was needed?) so I could actually see evidence of my mesh (because my wiremesh was the same color as the base material and thus invisible...) and with it everything works now after some fiddling.