|
GL question : image upside down in Render In ImageHi ! I'm working on a plugin that will be used this next week end for a performance. This plugin is rendering GL lines and triangles, and I have this trouble : my render is always upside down in render in image. Is there a good practice to manage this render in image / GL issue ? I'm looking at the source code of many of the generous people posting their codes, but I can't find how ! I don't know GL at all for the moment. it'll be my next step :-) Here is the (simple) code I'm using, I know there's something to do with the glOrtho and the width and height, but what... : double width = context.bounds.size.width; double height = context.bounds.size.height; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-(width/2.) , (width/2.), -(height/2.) , (height/2.), -1, 1); if(self.inputBlendMode == 0) { glDisable(GL_BLEND); } else if(self.inputBlendMode == 1) { glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } else if(self.inputBlendMode == 2) { glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); } else if(self.inputBlendMode == 3) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); // RENDER for (id triangulation in trianglesArray) { for (id triangle in triangulation) { if (self.inputMode == 0 || self.inputMode == 2) { glColor4f(1., 1., 1., 0.5); glBegin(GL_TRIANGLE_FAN); { for (id edge in triangle) { glVertex2d([[edge objectAtIndex:0] doubleValue], [[edge objectAtIndex:1] doubleValue]); } } glEnd(); } if (self.inputMode == 1 || self.inputMode == 2) { glLineWidth((GLfloat)1.); glColor4f(1., 0., 0., 1.); glBegin(GL_LINE_LOOP); { for (id edge in triangle) { glVertex2d([[edge objectAtIndex:0] doubleValue], [[edge objectAtIndex:1] doubleValue]); } } glEnd(); } } } glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); glPopMatrix(); Thank you !
|
I'm sorry that I didn't remember I had already asked this question one year ago : http://kineme.net/forum/Programming/RenderinImageflipped
This "edit" makes me post you the right code (the previous one was a WIP one, sorry again) :
Thanks again.
Well... I managed to do it : I simply don't call the GL_PROJECTION ang glOrtho... I don't know if it is a good way to do it, but well... it works !
You should not need to set the viewport or the ortho coordinates, really you should just blast out vertices assuming you are a consumer patch that just draws geometry. QC will handle the GL State setup for your (projection, ortho, viewport according to the docs (this is spelled out for you), and dump you into GL_MODELVIEW matrix mode when it hits your consumer. Additionally, you don't really need to load identity on those transforms.
Something like the v002 Model loader does none of that setup,
essentially all we do is:
// setup the state defaults we need, capturing any changes the above attribs don't capture
// Draw our verts
A big big thank you vade !
Just have met the same problem. A shader comp from Shadertoy collection put into Render In Image patch flips vertically while simple comps don't...