Results 1 to 2 of 2

Thread: Problems with Qt OpenGL drawing a textured Quad

  1. #1
    Join Date
    Feb 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems with Qt OpenGL drawing a textured Quad

    Hallo,

    i use Qt 4.7 and want to draw a textured quad, because glDrawPixels is to slow. The texture changed every time i want to redraw, because it cames from a framegrabber.

    I Have read some tutorials, the problems is, that he only draw my first image, a gray 256x256 texture. The second one a 512x512 white not. The image buffers and sizes are changed correctly. So i miss something else.

    It will be nice if someone could help me.

    Here my paintGL method from my QGLWidget. A whole test project is attached.

    thanks

    Qt Code:
    1. void GUIGLView::glInit()
    2. {
    3.  
    4. }
    5.  
    6. void GUIGLView::paintGL()
    7. {
    8. qglClearColor(QColor(Qt::black));
    9. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    10.  
    11. // only do something if image is availible
    12. if(mImageData.imageBuffer == NULL)
    13. return;
    14.  
    15. QString debugString = QString("paintGL called with buffer: 0x%1, size %2").arg((int)mImageData.imageBuffer,8,16,QChar('0')).arg(mImageData.width);
    16. qDebug(debugString.toAscii().data());
    17.  
    18. // set projection - disable z-axis
    19. glMatrixMode(GL_PROJECTION);
    20.  
    21. //clear projection matrix
    22. glLoadIdentity();
    23.  
    24. //Creating an orthoscopic view matrix going from -1 -> 1 in each
    25. //dimension on the screen (x, y, z).
    26. glOrtho(0, 640, 480, 0, -1, 1);
    27.  
    28. //Now editing the model-view matrix.
    29. glMatrixMode(GL_MODELVIEW);
    30.  
    31. //Clearing the model-view matrix.
    32. glLoadIdentity();
    33.  
    34. //Disabling the depth test (z will not be used to tell what object
    35. //will be shown above another, only the order in which I draw them.)
    36. glDisable(GL_DEPTH_TEST);
    37.  
    38. // generate a texture
    39. glGenTextures(1, &mTextureID);
    40.  
    41. // enable texturing
    42. glEnable(GL_TEXTURE_2D);
    43.  
    44. //specify texture to use
    45. glBindTexture(GL_TEXTURE_2D, mTextureID);
    46.  
    47. // set texturing parameters
    48. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    49. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    50.  
    51. // copy image to texture
    52. glTexImage2D(GL_TEXTURE_2D, 0, mImageData.samplesPerPixel, mImageData.width, mImageData.height, 0, GL_RGB, GL_UNSIGNED_BYTE, mImageData.imageBuffer);
    53.  
    54. // draw a textured quad
    55. glBegin(GL_QUADS);
    56. glTexCoord2f(0,0); glVertex3f( 0, 0,0); //lo
    57. glTexCoord2f(0,1); glVertex3f(256, 0,0); //lu
    58. glTexCoord2f(1,1); glVertex3f(256, 256,0); //ru
    59. glTexCoord2f(1,0); glVertex3f( 0, 256,0); //ro
    60. glEnd;
    61.  
    62. glDeleteTextures(1, &mTextureID);
    63. mTextureID = 0;
    64. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2010
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with Qt OpenGL drawing a textured Quad

    One Problems solved, missing () behind glEnd(). Sometimes i hate compilers.

    But the screen is not correctly cleared.

Similar Threads

  1. drawing into QImage with OpenGL
    By produktdotestow in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2010, 13:10
  2. Flickering when drawing Qt widgets over an OpenGL window
    By ksierens in forum Qt Programming
    Replies: 0
    Last Post: 31st May 2010, 14:31
  3. Creating QUAD Elements would openGL be better than Qt
    By sujan.dasmahapatra in forum General Programming
    Replies: 4
    Last Post: 17th October 2009, 10:49
  4. Mouse Drawing in opengl
    By sdastagirmca in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2009, 09:32
  5. drawing in opengl
    By sdastagirmca in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2009, 14:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.