GL points and wireframe

franz's picture

Hi, i'm hacking the GLheightfield plugin to suit my needs (it accepts CIimages as inputs, esp. Isight, so it is much handier for deformations than using built-in GLSL shader procedure - issues have already been discussed-).

Q1: I noticed that in the KinemeGL Points patch, users had the ability to set an image texture to the points. I am wondering how this could be achieved on a mesh: having each point of the model (a heightfielded grid) textured with an image.

Right now, my code looks like this:

if(self.inputWireFramePoints) { glGetIntegerv(GL_POLYGON_MODE, saveModes); glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); glPointSize(6); ... bla bla bla

Any advice ?

Q2: For the Kineme Grid renderer, you coded an option to display quads in wireframe (and not triangles) I was also wondering how this could be achieved ? I'm using: glDrawElements(GL_TRIANGLES, (kSize - 1) * (kSize - 1) * 6, GL_UNSIGNED_INT, _indices); so i guess i could replace GL_TRIANGLES by GL_QUADS and compute indices in another way, but this doesn't produce expected results when in glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

EDITED: I'm currently messing around with glEdgeFlag

Any help welcome.

Thxx

cwright's picture
advice

Point Texturing is a simple procedure. Generally you just need this: glEnable(GL_POINT_SPRITE); glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

(In unofficial-API-land, you need to fiddle with the inputimages as well to get them have proper coordinates for point sprites ------ I remember fighting with this in the official API and never getting it to work. I'm no official-api jockey though).

The GLGridRenderer's quad wireframe is basically a hack -- it does a glBegin(GL_LINE_STRIP); and then draws the 4 sides of each quad in the mesh. Looking back at it now, it's probably very slow because it double-draws over half of the lines (among all the other reasons for it being slow, like not using VBOs or anything).

GLTools 0.4's source is available, that may be handy to look through for (badly written, unoptimized) GL code :) (Kineme 3D's gl code is much more optimized, though it still has room for improvement too :)

franz's picture
source

thanks for the advice. Where is the source code located ?

cwright's picture
on the page :)

http://kineme.net/QuartzComposerPatches/GLTools/0.4 -- 3rd file to download :) (I added it a couple days later)

franz's picture
finally, after diving into

finally, after diving into the source, it turns out that: 1- My plug is based on the official API 2- It uses FBO to VBO method to generate geometry

so it is totally impossible to glue some part of your code over it.... (too bad)

it also turned out that some hard thinking is always rewarded, since i started to snif/snaf into the plug, and managed to do quad-wireframing by reconfiguring manually the indices (and skipping the 2 redundant vertex declaration in a quad) and using GL_QUADS insteas of GL_TRIANGLES.

I just step on another problem:

i use this method in order to get the wireframe colored according to some input color:

colorComponents = CGColorGetComponents(self.inputColor); glColor4f(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);

and if, once compliled, the color actually gets changed, the alpha component is NOT taken into account. Alpha stays at 1 what ever you set within QC. Is this behaviour normal, or has it to do with GL_BLEND something (which i don't use.... so maybe i should investigate this way)

Sorry if i don't post this directly on QCdev, but hey, a quick googling shows me that half of my problems have already been asked by some guy called (guess what) .... cwright

cwright's picture
Alpha in QC

The default render mode for GL stuff seems to be "Replace", which, as you've noticed, does Not use alpha. Blend will use alpha, and maybe Add (I don't think it does, but I could be mistken since I don't use Add very often).

glEnable(GL_BLEND) (something like that in the GLTools source) will turn on blender, be sure to turn it off when you're done (the correct way to handle this is like this:

GLuint oldBlendMode; glGetIntegerv(GL_BLENDblahblah, &oldBlendMode);

... do cool stuff ...

glBlend(oldBlendMode); return YES;

there are 2 ints though (source and dest blends), so it's a bit more than that, but the glGet and set are all in the source, so you can find it pretty easily.