0

I use my own QGraphicsItem-based class for drawing in QGraphicsScene. I also use FTGL for text rendering. Everything works fine until I start using shaders. My frame update logic is following: in MyGraphicsItem::paint I first update frame with following code (for YUV images):

glEnable(GL_MULTISAMPLE);

QGLFunctions glFuncs(QGLContext::currentContext());

glFuncs.glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE, tex0Id);
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);


glFuncs.glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_RECTANGLE, tex1Id);
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, width/2, height/2, GL_LUMINANCE, GL_UNSIGNED_BYTE, data + (width * height));

glFuncs.glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_RECTANGLE, tex2Id);
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, width/2, height/2, GL_LUMINANCE, GL_UNSIGNED_BYTE, data + (int)(5 * width * height) / 4);        

shader->bind(width, height);

and after that I render text:

glDisable(GL_TEXTURE_RECTANGLE);

glOrtho(0, WIDTH, 0, HEIGHT, 0, 1);
glColor3f(0.0, 1.0, 0.0);

bufferFont.Render("This is a text", -1, FTPoint(150, 200, -1.0));

But instead of text there is a rectangle. I tried to disable GL_TEXTURE_2D, but it didn't work. How can I use both shaders and FTGL

user2123079
  • 656
  • 8
  • 29
  • 1
    you can not mix arbitrary shaders with code that is suited for fixed function. You have two options 1. unbind shaders for text rendering 2. rewrite your shaders to support all what is needed for the text render (I assume 2D single texturing , glColor, blending and may be also depth). if you are using higher GL versions where you have to use VAO then this is not possible other then using [default attriuteb locations](http://stackoverflow.com/a/20574219/2521214) which only **nVidia** drivers support/define. – Spektre Feb 02 '17 at 08:46
  • @Spektre: In my experience, also Intel Integrated graphics supports default attribute locations. They do appear to have other defaults compared to the NVidia ones, though. For instance, the default colour when no colour attribute is specified is white as opposed to black in the case of NVidia. – Bartvbl Feb 02 '17 at 09:18
  • @Bartvbl well if they have the same locations across few gfx driver versions that does not mean they support it (it can be just include inheritance that can change at any time). **nVidia** clearly stated that they do so it is much safe assume the locations will be the same even in a year or two. I am not aware of any such statement from any other Vendor. – Spektre Feb 02 '17 at 10:05
  • @Spektre You are of course entirely right about that. I believe there may even be inconsistencies in which drivers support it on which platform. Regardless, it's undefined behaviour according to the OpenGL specification to render without a shader enabled. These vendors have decided to use their own, but technically they can do whatever they please and still be compliant. – Bartvbl Feb 02 '17 at 10:55

0 Answers0