Results 1 to 6 of 6

Thread: texture mapping, loading up an image, DevIL

  1. #1
    Member Newbie
    Join Date
    Oct 2011
    Posts
    34

    texture mapping, loading up an image, DevIL

    I keep getting a black, blue or white screen depending on the alterations I make to my code but the image does not upload. I think the problem is with the display function. I have functions in the display function but I don't think that should matter. My display function looks something like this:

    void display(void)
    {

    //clear the screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(Angle, 0.0, 0.0, 0.0);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

    // Select the texture to use
    glBindTexture(GL_TEXTURE_2D, texture[0]);


    // Draw our texture
    glEnable(GL_TEXTURE_2D);


    //Nose
    drawTriangle();

    //Face
    circle (250, 250, 400);


    //Inner Eyes
    glLoadIdentity();
    circle(200, 280, 10);
    drawCircle1(-30, 280, 10);

    //Eye lids
    glLoadIdentity();
    glScalef(0.6,0.2,0);
    circle(530, 2400, 60);
    circle(-150, 2150, 60);

    //Arc for eyebrows
    drawArc(500, 500, -70, -140, 100);
    drawArc(270, 500, -70, -140, 100);

    //Mouth
    drawArc(380, 250, 110, -180, 180);
    // drawArc(380, 100, -100, -180, 180);
    drawLine();

    glDisable(GL_TEXTURE_2D);

    // ----- Stop Drawing Stuff! ------

    glfwSwapBuffers(); // Swap the buffers to display the scene (so we don't have to watch it being drawn!)

    }

    An example of the circle function is:


    void circle(GLint x, GLint y, GLint radius)
    {
    float angle;

    glTranslatef(300, 100, 0.0);
    glTranslatef(0.0,150.0, 1.0);

    glColor3f(0.0f, 1.0f, 0.0f);
    glBegin(GL_LINE_LOOP);
    for (int i = 0; i < 100; i++)
    {
    angle = i*2*PI/100;
    float X = x + (cos(angle) * radius);
    float Y = y + (sin(angle) * radius);
    glVertex2f(X, Y);
    //glVertex2f(x + (cos(angle) * radius), y + (sin(angle) * radius));
    }
    glEnd();

    }
    And my main function looks like this:

    int main (int argc, char** argv)
    {
    glutInit (&amp;argc, argv);
    // Initialize GLUT
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition (100, 100);
    glutInitWindowSize (winWidth, winHeight); // Set the initial Window's width and height
    glutCreateWindow ("Facial Expression Recognition Project");// Create window with the given title


    glutDisplayFunc (display); // Register callback handler for window re-paint event
    glutMainLoop ( ); // Enter infinitely event-processing loop

    }
    Could it be the display function or it is something else?

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    7

    Re: texture mapping, loading up an image, DevIL

    OpenGL does not have the concept of a separate Model and View Matrix. Instead it has one combined matrix the MODEL_VIEW.

    This means you need to ensure when you draw your model that you preserve the VIEW portion of the Model-view-matrix. You can do this by using the pushMatrix() and PopMatrix commands to encapsulate each part of your model drawing routines.

    This may be your issue.

    e.g.

    setup camera

    .... draw face routine
    pushMatrix(GL_MODELVIEW)
    specify translate commands as necessary
    specify rotate commands as necessary
    popMatrix()

    ... draw Eyes
    pushMatrix(GL_MODELVIEW)
    specify translate commands as necessary
    specify rotate commands as necessary
    popMatrix()

    etc....

  3. #3
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,676

    Re: texture mapping, loading up an image, DevIL

    It could be anything. That's why it's a good idea to change only one thing at a time.

    If you want to test your texture upload code, write a simple application that draws a single quad to the screen that has a texture mapped to it. That texture should come from memory (ie: create an array of some data, perhaps the same value for each texel, whatever, and upload it with glTexImage2D). Once you have that working, then you know that your display code works. Then you change where your texture comes from: load it with DevIL and upload what it gives you.

    If it continues to work, then you know your loading code is fairly solid. If it stops working, then you know you did something wrong in your loading code.

    Don't try to change too much all at once.

    Also, do you intend to draw lines that use the texture? If not, then you should unbind and disable the texture unit, and then use glTexEnv to just take the per-vertex color.

  4. #4
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: texture mapping, loading up an image, DevIL

    You are not specifying texture coordinates in your circle drawing function, so all vertices will have the same texture coordinates (whatever they were last set to) and a single pixel of your texture gets mapped to the whole primitive.

  5. #5
    Member Newbie
    Join Date
    Oct 2011
    Posts
    34

    Re: texture mapping, loading up an image, DevIL

    Wow. Thanks everyone for your prompt response. I've taken note of all your comments and suggestions. I'll work on it right away and let you know if it works. Thanks so much again.

  6. #6
    Member Newbie
    Join Date
    Oct 2011
    Posts
    34

    Re: texture mapping, loading up an image, DevIL

    carsten neumann was right. The problem was with my texture coordinates. Once I took care of that, I was able to upload my image. Sorry it took a while for me to respond. Thanks.

Similar Threads

  1. Error loading textures with DevIL
    By catasturslykid in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-29-2016, 08:34 AM
  2. Memory leak in texture loading with loadImage using Devil
    By opty2001 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-04-2013, 09:39 PM
  3. Texture Mapping/Loading an image using SOIL
    By annette in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-16-2011, 10:44 AM
  4. OpenGL Texture loading using Devil
    By Pan007 in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 10-06-2011, 01:58 AM
  5. Image loading and processing (for texture mapping)?
    By daviem01 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-22-2001, 12:05 PM

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