Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:50+00:00 2026-06-15T10:45:50+00:00

I am trying to map a 1D texture on a solid teapot, it works

  • 0

I am trying to map a 1D texture on a solid teapot, it works fine I would to add the lights.
When I call glMaterialfv, the colour of the material overrides the colour of the texture.So in this trivial example I just paint the teapot of yellow.But if I also use glMaterialfv, then the teapot takes the colour that I have specified in glMaterialfv.
I would know how is possibile to set the colour of the material to have the same colour of the texture in all it’s points.This is what I’ve tried, thinking that it was working:

#import <OpenGL/OpenGL.h>
#import <GLUT/GLUT.h>
#import <stdlib.h>
#import <math.h>

void makeRound(GLfloat* angle);

GLuint width=640, height=480;
GLfloat angle=0.0;
GLuint texture;
GLfloat (*pixels)[3];
float coeff[]= {1, 0 ,0 ,0};

inline void makeRound(GLfloat* angle)
{
    int intValue= *angle;
    GLfloat decimal= *angle - floor(*angle);
    intValue%=360;
    *angle= intValue+decimal;
}

void init()
{

    glEnable(GL_DEPTH_TEST);
    glViewport(-500, -500, 1000, 1000);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45, width/(float)height, 1, 1000);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0, 0, -100, 0, 0, 0, 0, 1, 0);

    // Lights

    glShadeModel(GL_FLAT);

    glMaterialfv(GL_FRONT, GL_AMBIENT, (const GLfloat[]) {1,0,0} );
    glMaterialfv(GL_FRONT, GL_DIFFUSE, (const GLfloat[]) {1,0.25,0} );
    glMaterialfv(GL_FRONT, GL_SPECULAR, (const GLfloat[]) {1,0.75,0} );
    glMaterialfv(GL_FRONT, GL_SHININESS, (const GLfloat[]) {1,1,0} );

    glLightfv(GL_LIGHT0, GL_AMBIENT, (const GLfloat[]) {0,0,0} );
    glLightfv(GL_LIGHT0, GL_DIFFUSE, (const GLfloat[]) {1,1,0} );
    glLightfv(GL_LIGHT0, GL_SPECULAR, (const GLfloat[]) {0.5,0.5,0} );

    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    // Texture

    pixels= calloc(256,sizeof(GLfloat[3]));
    for(GLuint i=0; i<256; i++)
    {
        pixels[i][0]= pixels[i][1]= 1.0;
    }

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_1D, texture);
    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_RGB, GL_FLOAT, pixels);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGenfv(GL_S, GL_OBJECT_PLANE, coeff);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_1D);
    glEnable(GL_CULL_FACE);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);
    glEnable(GL_CW);
    glCullFace(GL_BACK);
}

void display()
{
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3ub(255, 255, 255);
    glPushMatrix();
    glRotatef(angle, 0, 1, 0);
    glBindTexture(GL_TEXTURE_1D, texture);
    glutSolidTeapot(10);
    glPopMatrix();

    glFlush();
}

void keyboard(unsigned char key, int x, int y)
{
    if(key=='+')
    {
        angle+=5.0;
    }
    else if(key=='-')
    {
        angle-=5.0;
    }
    else
    {
        return;
    }
    makeRound(&angle);
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(width, height);
    glutCreateWindow(argv[0]);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    init();
    glutMainLoop();
    return 0;
}

But the teapot is not yellow, and if I cancel all that lines that initialize the lights and materials the teapot is yellow.
I would like to do something like:

glMaterialfv(GL_FRONT, GL_AMBIENT, color_of_the_texture_at_every_pixel );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:45:50+00:00Added an answer on June 15, 2026 at 10:45 am

    The color of the material is multiplied by the color of the texture. If you want all the original texture color to come through, then you need to make the material be white.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to map a different texture on each side of a cube
I am trying to map a texture to a quad in pyglet using the
I am trying to map a texture to a circle using GL_POLYGON using this
I am trying to map a texture onto a square where the texture stretches
I am trying to understand the concept of texture mapping. I tried to map
I'm trying to map a globe texture onto a sphere. I'm using a plate
While using the UDK im trying to paint the height map with different texture,
I'm trying to make a Q3BSP map information debugger. I'm stuck at texture debugger
Trying to map the following schema using the Entity Framework. A Customer can have
Im trying to map urls to numbers in a range [0,50] for porting, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.