Results 1 to 2 of 2

Thread: basic opengl problem

  1. #1
    Join Date
    Aug 2009
    Location
    LOL Land
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default basic opengl problem

    this is an opengl problem but because it's partially qt, i thought it best to ask here. im new to opengl so bear with me.

    i have data for a texture and i bind the texture in the init code and draw it in the paint code and yet only the black background is shown.

    what am i doing wrong?

    note: when proper opengl code is put in this class, it does draw, so it's not another part of my project, it's in this class specifically.

    Qt Code:
    1. static GLint block[] =
    2. {
    3. 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xff000000, 0xffe04000, 0xffe04000,
    4. 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xff000000, 0xffe0e0a0,
    5. 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe04000, 0xff000000,
    6. 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe04000, 0xff000000,
    7. 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe04000, 0xff000000,
    8. 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000,
    9. 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe0e0a0, 0xffe0e0a0, 0xff000000, 0xff000000, 0xffe0e0a0,
    10. 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0,
    11. 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000,
    12. 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000,
    13. 0xffe0e0a0, 0xffe04000, 0xff000000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xff000000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000,
    14. 0xffe0e0a0, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe0e0a0, 0xffe0e0a0, 0xff000000, 0xff000000, 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0,
    15. 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0,
    16. 0xffe04000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xffe0e0a0,
    17. 0xffe04000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xff000000, 0xffe04000, 0xffe04000, 0xff000000, 0xff000000, 0xff000000,
    18. 0xff000000, 0xffe0e0a0, 0xffe04000, 0xffe0e0a0, 0xffe04000, 0xffe04000, 0xffe0e0a0, 0xff000000, 0xffe0e0a0, 0xff000000, 0xff000000, 0xffe0e0a0, 0xffe0e0a0, 0xff000000, 0xff000000, 0xffe0e0a0,
    19. };
    20.  
    21. GLDemo::GLDemo( QWidget* parent )
    22. : QGLWidget( parent )
    23. {
    24. }
    25.  
    26. void GLDemo::initializeGL()
    27. {
    28. qglClearColor( Qt::black ); // Let OpenGL clear to black
    29. QImage pix((const uchar*)block, 16, 16, QImage::Format_ARGB32);
    30. object = bindTexture(pix, GL_TEXTURE_2D, GL_RGB8);
    31. glShadeModel( GL_FLAT );
    32. }
    33.  
    34. void GLDemo::paintGL()
    35. {
    36. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    37. glLoadIdentity();
    38. drawTexture(QPointF(0, 0), object, GL_TEXTURE_2D);
    39. }
    40.  
    41. void GLDemo::resizeGL( int w, int h )
    42. {
    43. glViewport( 0, 0, (GLint)w, (GLint)h );
    44. glMatrixMode( GL_PROJECTION );
    45. glLoadIdentity();
    46. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
    47. glMatrixMode( GL_MODELVIEW );
    48. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: basic opengl problem

    Do you take into consideration that QImage stores data in a format different than what OpenGL expects? Why do you go through QImage anyway? Why don't bind the texture directly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Basic hash problem
    By feraudyh in forum Newbie
    Replies: 6
    Last Post: 4th December 2009, 08:59
  2. QT 4.5 + .config problem with Basic XLib?
    By qoo in forum Installation and Deployment
    Replies: 4
    Last Post: 5th August 2009, 11:52
  3. basic inherited or vector problem?
    By mickey in forum General Programming
    Replies: 8
    Last Post: 14th February 2007, 20:29
  4. basic problem of config qmake
    By Shuchi Agrawal in forum Qt Tools
    Replies: 10
    Last Post: 10th January 2007, 09:31
  5. basic qt opengl problem
    By kingslee in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2006, 15:26

Tags for this Thread

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.