Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. Qt OpenGL gltexture
Forum Updated to NodeBB v4.3 + New Features

Qt OpenGL gltexture

Scheduled Pinned Locked Moved Qt in Education
4 Posts 2 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XLeopard
    wrote on last edited by
    #1

    How can I paste a pixelmap of the earth on a solid sphere.
    But I am not able to deal with the texture coords.
    Can you show me a piece of code?

    1 Reply Last reply
    0
    • X Offline
      X Offline
      XLeopard
      wrote on last edited by
      #2

      soved

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        Can you post your solution so that others who might be searching the forums with a similar question might benefit?

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          XLeopard
          wrote on last edited by
          #4

          Attention:you must add glu.h or glut.h manually in you QtOpenGL file
          I think one must understand though only core code related to texture is showed.

          @#include <QtGui>
          #include <QtOpenGL>
          #include <glut.h>

          void GLwidget::loadTextures()
          {
          glEnable(GL_TEXTURE_2D);
          QImage text[3],buff[3];
          if(!buff[0].load("./sun.bmp")
          ||!buff[1].load("./earth.bmp")
          ||!buff[2].load("./moon.bmp")){
          printf("Load Image failed!\n");
          }
          text[0] = QGLWidget::convertToGLFormat(buff[0]);
          text[1] = QGLWidget::convertToGLFormat(buff[1]);
          text[2] = QGLWidget::convertToGLFormat(buff[2]);

          glGenTextures(3,&texture[0]);

          glBindTexture( GL_TEXTURE_2D, texture[0] );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
          glTexImage2D( GL_TEXTURE_2D, 0, 3, text[0].width(), text[0].height(), 0,
          GL_RGBA, GL_UNSIGNED_BYTE, text[0].bits() );

          glBindTexture( GL_TEXTURE_2D, texture[1] );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
          glTexImage2D( GL_TEXTURE_2D, 0, 3, text[1].width(), text[1].height(), 0,
          GL_RGBA, GL_UNSIGNED_BYTE, text[1].bits() );

          glBindTexture( GL_TEXTURE_2D, texture[2] );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
          glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
          glTexImage2D( GL_TEXTURE_2D, 0, 3, text[2].width(), text[2].height(), 0,
          GL_RGBA, GL_UNSIGNED_BYTE, text[2].bits() );
          }@
          @
          void GLwidget::paintGL()
          {GLUquadricObj *quadratic = gluNewQuadric();
          glBindTexture(GL_TEXTURE_2D, texture[0]); //the same with texture[1],[2]
          glPushMatrix();
          gluSphere(quadratic,sunRadius,100,100);
          glPopMatrix();
          }@
          @
          void GLwidget::initializeGL(){
          glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
          glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
          }@

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved