Results 1 to 7 of 7

Thread: OpenGL textured quad not displaying correctly

  1. #1
    Join Date
    Mar 2011
    Location
    West Jordan, Utah
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default OpenGL textured quad not displaying correctly

    This code is a port from a working project I did in OpenTK. The quad doesn't seem to display properly. Any help you can give would be great.
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenGL textured quad not displaying correctly

    Come on man, you expect someone to dig your project's source, because something is not working as you wish. You didn't even bother to tell what's the problem exactly, no rendering OpenGL code, nothing.
    Any help you can give would be great
    Yeah, I can give you a hint - be more specific.

  3. #3
    Join Date
    Mar 2011
    Location
    West Jordan, Utah
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL textured quad not displaying correctly

    No Problem, sorry I don't usually ask for help. I just thought including all of the code would make it easier to run and see. I will post a couple of screen shots and the texurize function code. I hope that will help. I attached a working OpenTK application so you can see what the image should look like when rendered properly. Again apologies for the lack of details ...

    Qt Code:
    1. void GLWidget::texturize()
    2. {
    3. for (uint i = 0; i < imageArrayLength; i++)
    4. dspArray[i] = lutArray[imageArray[i]];
    5. /*ushort val;
    6.   for (uint i = 0; i < imageArrayLength; i++)
    7.   {
    8.   val = imageArray[i];
    9.   dspArray[i] = lutArray[val];
    10.   }*/
    11.  
    12. glGenTextures(1, &textureId);
    13. glBindTexture(GL_TEXTURE_2D, textureId);
    14.  
    15. // when texture area is small, bilinear filter the closest mipmap
    16. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
    17. GL_LINEAR );
    18. // when texture area is large, bilinear filter the original
    19. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    20.  
    21. // the texture wraps over at the edges (repeat)
    22. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
    23. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
    24.  
    25. //glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, image_array2D );
    26. glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, imageSize.width(), imageSize.height(), 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, dspArray );
    27. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GLWidget::paintGL()
    2. {
    3. //glClear(GL_COLOR_BUFFER_BIT);
    4. //qglColor(Qt::blue);
    5. //glMatrixMode(GL_MODELVIEW);
    6. //glLoadIdentity();
    7.  
    8. glScalef(scale, scale, 1.0f);
    9. glTranslated(-centerImage.x(), centerImage.y() - height, 0.0f);
    10.  
    11. //glColor3i(1.0,1.0,1.0);
    12. qDebug() << "-centerImage.x(): " << -centerImage.x() << " centerImage.y() - height: " << centerImage.y() - height;
    13.  
    14. glBegin(GL_QUADS);
    15. glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, (GLfloat)height);
    16. glTexCoord2f(1.0f, 0.0f); glVertex2f((GLfloat)width, (GLfloat)height);
    17. glTexCoord2f(1.0f, 1.0f); glVertex2f((GLfloat)width, 0.0f);
    18. glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
    19. glEnd();
    20.  
    21. swapBuffers();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GLWidget::resizeGL(int w, int h)
    2. {
    3. width = w;
    4. //height = h;
    5. height = h?h:1;
    6. w2 = (double)width / 2;
    7. h2 = (double)height / 2;
    8.  
    9. scale = 1024;
    10.  
    11. while(imageSize.width() * scale > width || imageSize.height() * scale > height)
    12. scale /= SCALE_FACTOR;
    13.  
    14. qDebug() << "Scale: " << scale;
    15.  
    16. centerImage.setX((int)w2);
    17. centerImage.setY((int)h2);
    18.  
    19. glViewport(0, 0, (GLint)width, (GLint)height);
    20. glMatrixMode(GL_PROJECTION);
    21. glLoadIdentity();
    22. glOrtho(-w2, w2, -h2, h2, -1.0, 1.0);
    23. glMatrixMode(GL_MODELVIEW);
    24. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by vmsgman; 2nd May 2011 at 15:49. Reason: more information

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenGL textured quad not displaying correctly

    Ok, sorry for being rude, this forum is just full of guys asking to do their homework for them
    Are you sure this is a display problem ? Have you tried to convert your image to QImage and save it on disk ? For me it looks like wrong image format is selected for display, so if you manage to convert your image to QImage, you'll know which image format to choose.
    I think your image reading method needs corrections, because you allocate an array of size "aLen" and then read the file content with max size set to "len", which is less than allocated size, so resulting data can be deficient.

  5. The following user says thank you to stampede for this useful post:

    vmsgman (2nd May 2011)

  6. #5
    Join Date
    Mar 2011
    Location
    West Jordan, Utah
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL textured quad not displaying correctly

    No worries, I've been out of school for years, way to many to mention. This is a project I am working on for work. I just wanted to say that so you know. So I understand any level of help, is given with that in mind. I know people's time is valuable. So thanks for helping me. So the image data type is ushort (unsigned short integer) 16 bits per pixel. There is a header that has some information in it. height, width, etc. it is 2048 bytes long. after that it goes from top left to bottom right corner in ushorts. The read function needs a length which since I have already read the header if the file type is .viv, which is what I attached in the zip file. Then we read the header and then fill in the image array. I believe I have tested the imageArray and the dspArray (this is simply a window/leveled (256) version of the imageArray) and have good values. It just happens to not display correctly. So I am thinking that I must have something wrong with my OpenGL code, but since I am asking for help, I will explain the question you asked above.

    len = width * height // Of the image
    aLen = # of bytes needed to read to fill in the image array, which is width * height * 2 (2 bytes per pixel)

    Thanks for your help!

  7. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenGL textured quad not displaying correctly

    Alright, I know what's the problem - when you call "texturize", the glwidget's opengl context is not current, so you have to call texturize() inside initializeGL(), or call makeCurrent() in texturize() yourself (before any OpenGL calls). Image is displayed correctly (I mean looks like the one attached to your post) after one of above modifications. There are some problems when resizing, but I guess that's separate issue.

  8. The following user says thank you to stampede for this useful post:

    vmsgman (4th May 2011)

  9. #7
    Join Date
    Mar 2011
    Location
    West Jordan, Utah
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL textured quad not displaying correctly

    Thanks alot, I can work on the other stuff. I certainly appreciate the help!

Similar Threads

  1. Problems with Qt OpenGL drawing a textured Quad
    By Halcom in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2010, 12:27
  2. QImage displaying through OpenGL
    By strateng in forum Newbie
    Replies: 0
    Last Post: 23rd March 2010, 04:35
  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. Replies: 7
    Last Post: 27th June 2007, 09:34
  5. Triple / quad click
    By bits in forum Newbie
    Replies: 1
    Last Post: 6th June 2006, 05:40

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.