# openGl

## GLSL : Graphic card bug ? QC bug ? Bad code ?

Hi !

I've been fascinated for months with toneburst CI implementation of Light Scattering, from GPU Gems. So I decided to try to make a GLSL Shader with it. In fact, while googling I found some simple GLSL code coming directly from GPU Gems (http://stackoverflow.com/questions/13489703/sfml-2-0-glsl-volumetric-lig...).

But, it is very buggy, and it looks like a graphic card bug, or maybe I'm not dealing with the texture properly, or... could it be a QC bug ? (I'm on 10.8)

I would be extremely grateful for any advice on this :-)

Thanks.

Ben

Hey, there used to be a Kineme patch to render wireframes in quad mode (Kineme GL Grid Renderer), but it seems to have disappeared recently? Is there a way to do this with a glsl shader?

## iniTree - draw your own recursion tree

Hello there, I just want to share with you a simple that draws a ternary tree. The algorithm is very simple and uses recursion. Here is what it does in pseudocode (for n-ary tree):

`main{   …   max_levels = 10      //the max num of levels   tree(initLenght, 1);   …} tree(length, level){   …   if(level<max_levels){   //is the end of the recursion?      n = 3      //it is a ternary tree      for(x=0; x<n; <++){            pushMatrix()         rotate ((360 / n)*x) along y axis         rotate (aperture) along z axis         drawLine(0,0,0, 0,length,0)   //from 0,0,0 to 0,length,0         translate(0,length,0)         tree(lenght/2, level+1)      //recursive call         popMatrix()      }   }}`

As you can see, I used glRotate/glTranslate and glBegin(GL_LINES)/glEnd() calls, in old OpenGL style. Maybe this is the reason why with more than 8/9 levels I don't obtain good performance. Using vbo will result in better performance, but I'm still not sure about how to do that.

It is a very simple plugin, but if used in audio-reaction compositions I think it can produce interesting results. So let me know if someone use it in some cool way! :)

## Rendering huge amount of vertices (VBO)

Hi to all, I'm developing a plugin that allows you to render a set of vertices randomly distributed in space. I’d like to draw a huge amount of vertices at the same time: to do this I tried to use OpenGL Vertex Buffer Object (VBO), because I read that it allows vertex array data to be stored in high-performance graphics memory on the server side and promotes efficient data transfer.

This is my approach:
* Generate a new buffer object with glGenBuffersARB().
* Bind the buffer object with glBindBufferARB().
* Copy vertex data to the buffer object with glBufferDataARB().

so in my startExecution plugin function I wrote:

`- (BOOL) startExecution:(id<QCPlugInContext>)context{   CGLContextObj cgl_ctx = [context CGLContextObj];    glGenBuffersARB(1, &VBUFFERNAME);   glBindBufferARB(GL_ARRAY_BUFFER, VBUFFERNAME);//vcArray is defined as float vcArray[numV*3]   glBufferDataARB(GL_ARRAY_BUFFER, sizeof(vcArray), vcArray, GL_DYNAMIC_DRAW_ARB);   glVertexPointer(3, GL_FLOAT, 0, 0);    return YES;}`

and in my execute plugin function I do this:
* Update vertices in vcArray using glBufferSubDataARB()
* Draw them using glDrawArrays()

`- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments{   CGLContextObj cgl_ctx = [context CGLContextObj];    //update vcArray vertices   updateVertices();    glEnableClientState(GL_VERTEX_ARRAY);   glBindBufferARB(GL_ARRAY_BUFFER, VBUFFERNAME);   {      glDrawArrays(GL_LINE_STRIP, 0, numV*3);      [self calcVertices];      glBufferSubDataARB(GL_ARRAY_BUFFER, 0, sizeof(vcArray), vcArray);   }   glDisableClientState(GL_VERTEX_ARRAY);   glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);    return YES;}`

..the problem is that I can’t get noticeably performance improvements than the immediate mode rendering: they are the same! For example, using VBO I got 60 FPS with 2.500 vetices, 40 FPS with 5000 verices, and 10 FPS with 20.000 vertices.. and that are the same performance I got in immediate mode, using simple code like these:

`glBegin(GL_LINE_STRIP);for(x = 0; x<numV; x++){   glVertex3f(v[x][0], v[x][1], v[x][2]);}glEnd();`

..am I missing something in the VBO approach? Why I can’t get performance improvements?

Thank you, Luke

## GTTextureTransform ("skanky" sdk patch): Release

http://www.georgetoledo.com/2011/03/gttexturetransform.html

This is skanky Quartz Composer plugin, environment macro, that transforms the GL Texture matrix.

...so, this means that in this environment you can do things like zoom, offset, or rotate texture through OpenGL function.

For example, one can rotate the texture on a sphere while keeping vertex positions the same, or one can zoom image on a sprite without using core image, etc.