Results 1 to 3 of 3

Thread: OpenGL Texturing mapping and coordinates strange Issue

  1. #1
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    3

    Exclamation OpenGL Texturing mapping and coordinates strange Issue

    Here I load textures:

    Code :
        glGenTextures(sceneList.count(), &mTextureID[0]);
     
        for (QList<SceneObject*>::ConstIterator i = sceneList.begin();i!=sceneList.end();++i) {
            Mesh* p = dynamic_cast<Mesh*>(*i);
            if(p){
                if (p->HasTexture()){
                    QImage* a =  p->Mat().GetTexture()->GetImage();
                    *a= QGLWidget::convertToGLFormat(*a);
                    glEnable(GL_TEXTURE_2D);
                    glBindTexture(GL_TEXTURE_2D, mTextureID[counter]);
                    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p->Mat().GetTexture()->ImageSize().width() , p->Mat().GetTexture()->ImageSize().height() , 0, GL_RGBA, GL_UNSIGNED_BYTE, a.bits());
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                    glDisable(GL_TEXTURE_2D);
                }
            }
            counter++;
        }
        }

    Then for every mesh i do this:

    Code :
        glBindTexture(GL_TEXTURE_2D, mTextureID[counter]);     //where counter=texture for current mesh
        ...
        const QList<Vector3D> vertices=p.Vertices();
        QList<Face>& faccie=p.Faces();
        int numerofacce=faccie.count();
        QList<Vector3D>& normals =p.Normals();
        int numerovertici=0
        for (int t = 0; t < numerofacce; ++t) {
            glEnable(GL_TEXTURE_2D);
            ...
            switch(f.numVertici) {
            case 1:
                a[1]++;
                face_mode = GL_POINTS;
                glBegin(face_mode);
                if(hasNormals)
                    glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
                    glVertex3fv(&vertices[lista[0]].pos[0]);
                numerovertici++;
                break;
            case 2:
     
                face_mode = GL_LINES;
                glBegin(face_mode);
                if(hasNormals){
                    glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
                    glVertex3fv(&vertices[lista[0]].pos[0]);
                    glNormal3fv(&normals[(f.normalIndex)[1]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
                    glVertex3fv(&vertices[lista[1]].pos[0]);
                }
                else{
                    glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
                    glVertex3fv(&vertices[lista[0]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
                    glVertex3fv(&vertices[lista[1]].pos[0]);
                }
                numerovertici+=2;
                break;
            case 3:
     
                face_mode = GL_TRIANGLES;
                glBegin(face_mode);
                if (numerovertici<p.Vertices().count()-3){
                if(hasNormals){
                    glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
                    glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
                    glVertex3fv(&vertices[lista[0]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
                    glNormal3fv(&normals[(f.normalIndex)[1]].pos[0]);
                    glVertex3fv(&vertices[lista[1]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici+2).x, p.TextureCoords().at(numerovertici+2).y);
                    glNormal3fv(&normals[(f.normalIndex)[2]].pos[0]);
                    glVertex3fv(&vertices[lista[2]].pos[0]);
                }
                else{
                    glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
                    glVertex3fv(&vertices[lista[0]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
                    glVertex3fv(&vertices[lista[1]].pos[0]);
                    glTexCoord2f(p.TextureCoords().at(numerovertici+2).x, p.TextureCoords().at(numerovertici+2).y);
                    glVertex3fv(&vertices[lista[2]].pos[0]);
                }
                numerovertici+=3;
                break;
            default: face_mode = GL_POLYGON; break;
            }
            glDisable(GL_TEXTURE_2D);
            ...

    **PRE:** Vertices number=number of texture coordinatess

    Every glTexCoord2f contains something like p.TextureCoords().at(numerovertici+2).x where

    *p* is the current mesh
    *TextureCoords()* is a QList<Vector3D> that contains all the 2D coords
    *at(numerovertici)* : takes from TextureCoords List the "numerovertici" element
    *.x* taking x coordinate

    So,I am using a vertices counter named "numerovertici" to remember how many vertices were drawn,and before drawing each vertex I am calling the correspondent texture coordinate.

    Is this a coordinates problem (I'm pretty sure they're ok) or should it be something else?

  2. #2
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    3
    This is how it looks right now (only half scene has been drawn to let you see the bottom texture).I have upload some screens because they're better than 1000 words.

    i.stack.imgur.com/d7GyG.jpg

  3. #3
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    3
    solved,was a coordinate problem (bad import)

Similar Threads

  1. Strange circle texturing
    By Popolerigolo in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-30-2017, 08:37 PM
  2. Mapping the real world into OpenGL coordinates
    By melatonin in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-01-2013, 04:08 AM
  3. strange OpenGL coordinates?
    By Vincent22 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-08-2011, 12:07 PM
  4. Problems mapping 2d window coordinates to 3d system coordinates
    By stefboombastic in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 01-04-2003, 01:11 AM
  5. Detailed texturing (Bump mapping) in OpenGL?
    By in forum OpenGL: User Software
    Replies: 3
    Last Post: 11-14-2000, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean