Results 1 to 10 of 10

Thread: OpenGL Texture Loading Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default OpenGL Texture Loading Problem

    Hi guys, I started playing around with OpenGL and initially, I was getting the message box popping up in the LoadGLWidget function call but I changed the type to void over int and that stopped happening... so by the looks of it, the image started to load without a problem. The problem however is that despite no error message box popping up, I see the coloured box, rather than having that box filled with my test image (both can be seen in the attachment. Any ideas as to what I'm doing wrong?

    Qt Code:
    1. #include "glwidget.h"
    2.  
    3. GLWidget::GLWidget(QWidget *parent) :
    4. QGLWidget(parent)
    5. {
    6. }
    7.  
    8. void GLWidget::initializeGL()
    9. {
    10. glEnable(GL_TEXTURE_2D);
    11. glClearColor(1,1,0.5,1);
    12.  
    13. glClearDepth(1.0f);
    14. glEnable(GL_DEPTH_TEST);
    15. glDepthFunc(GL_LEQUAL);
    16. }
    17.  
    18. //Setup viewport, projection etc...
    19. void GLWidget::resizeGL(int w, int h)
    20. {
    21.  
    22. if (h == 0)
    23. {
    24. h = 1;
    25. }
    26. }
    27.  
    28. //Draw the Scene
    29. void GLWidget::paintGL() //corresponds to DrawGLScene
    30. {
    31.  
    32. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    33. glLoadIdentity();
    34.  
    35. //glTranslatef(x, y, z)
    36.  
    37. //glTranslatef(0.0f,0.0f,-10.0f);
    38.  
    39. glBindTexture(GL_TEXTURE_2D, texture[0]);
    40.  
    41. glBegin(GL_QUADS);
    42. //Bottom Left
    43. glColor3f(0.5,0.5,0.5);
    44. glTexCoord2f(0.0f, 0.0f);
    45. glVertex2f(-1.0f, -1.0f);
    46.  
    47. //Top Left
    48. glColor3f(0.2,0.7,0);
    49. glTexCoord2f(0.0f, 1.0f);
    50. glVertex2f(-1.0f,1.0f);
    51.  
    52. //Top Right
    53. glColor3f(0.9,0.1,0.5);
    54. glTexCoord2f(1.0f, 1.0f);
    55. glVertex2f(1.0f,1.0f);
    56.  
    57. //Bottom Right
    58. glColor3f(0.6,0.6,0.6);
    59. glTexCoord2f(1.0f, 0.0f);
    60. glVertex2f(1.0f,-1.0f);
    61. glEnd();
    62.  
    63. /*
    64.   glBegin(GL_TRIANGLES);
    65.   glColor3f(0,1,0.7);
    66.   glVertex3f(-1,0,0);
    67.   glColor3f(0,0.1,0.5);
    68.   glVertex3f(1,0,0);
    69.   glColor3f(0.9,0.1,0);
    70.   glVertex3f(0,1,0);
    71.   glEnd();
    72. */
    73.  
    74. }
    75.  
    76. void GLWidget::LoadGLTexture()
    77. {
    78. QImage GLFormatImage;
    79. QImage QFormatImage;
    80.  
    81. if (!QFormatImage.load("actual path to the file with .bmp format"))
    82. {
    83. QMessageBox::information(this, "Error", "Could not load image");
    84. }
    85.  
    86. GLFormatImage = QGLWidget::convertToGLFormat(QFormatImage);
    87. glGenTextures(1, &texture[0]);
    88. glBindTexture(GL_TEXTURE_2D, texture[0]);
    89. glTexImage2D(GL_TEXTURE_2D, 0, 3, GLFormatImage.width(), GLFormatImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, GLFormatImage.bits());
    90. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    91. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    92. }
    To copy to clipboard, switch view to plain text mode 
    What I want.png
    What I get.jpg
    Last edited by Atomic_Sheep; 17th May 2012 at 17:50.

Similar Threads

  1. openGL bindtexture from within thread not working
    By thinkabit in forum Qt Programming
    Replies: 0
    Last Post: 23rd April 2011, 12:13
  2. Replies: 1
    Last Post: 4th February 2011, 03:34
  3. Replies: 0
    Last Post: 6th December 2009, 00:41
  4. Qt with OpenGL ES for ARM9 - All OpenGL ES tests have failed!
    By vinpa in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd December 2009, 10:10
  5. aux functions not working on opengl
    By john_god in forum Qt Programming
    Replies: 7
    Last Post: 11th April 2009, 12:23

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.