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 9001487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:26:36+00:00 2026-06-16T00:26:36+00:00

This program should allow the user to select the material of a teapot, that

  • 0

This program should allow the user to select the material of a teapot, that will change dynamically.So I made a menu.
I use setRGB (declared in a utility file) to set the color of an array of 3 GLfloat’s.
createMenu just creates the menu reading the voices from a va_list.
setMaterial sets the material, according to the value passed with an enumeration:

typedef enum
{
    BlackPlastic= 0,
    Brass,
    Bronze,
    Chrome,
    Copper,
    Gold,
    Peweter,
    Silver,
    PolishedSilver
}MaterialType;

I will omit the body of the functions that I have tested since they work:

int createMenu(void (*callback) (int),int key, const char* const first, ...)
{
    // creates a menu, the number of entries depends on the list length,
    // the value starts from zero
}

void setRGB( GLfloat* color, GLfloat red, GLfloat green, GLfloat blue)
{
    // Sets the color
}


void setMaterial (GLfloat** material, MaterialType type)
{
    // Sets the material color (ambient, diffuse, specular).
}

That’s the whole program.My fear here is that I am doing something wrong so that the teapot isn’t drawn because OpenGL enters in an invalid state.
The problem is that sometimes I don’t see the teapot drawn in the window, I just get a black window.Incredibly sometimes work and I see the teapot, and I am able to change the material colors.

#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#include "utility.h"
#include <stdlib.h>


GLfloat width=500, height=500;
GLfloat** material;
GLfloat light[3][3]= { {1,1,0}, {1,0.5,0}, {1,0,0} };


void menuCallback (int choice)
{
    setMaterial((GLfloat**)material, choice);
    glutPostRedisplay();
}

void init()
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-width/2, width/2, -height/2, height/2, 1, 1000);

    material= malloc(4*sizeof(GLfloat*));
    for(GLuint i=0; i<4; i++)
    {
        material[i]=malloc(3*sizeof(GLfloat));
    }

    setRGB(material[3], 1, 1, 0);
    setMaterial(material, BlackPlastic);
}

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

    glShadeModel(GL_FLAT);

    glMaterialfv(GL_FRONT, GL_AMBIENT, material[0] );
    glMaterialfv(GL_FRONT, GL_DIFFUSE, material[1]);
    glMaterialfv(GL_FRONT, GL_SPECULAR, material[2]);
    glMaterialfv(GL_FRONT, GL_SHININESS, material[3] );

    glLightfv(GL_LIGHT0, GL_AMBIENT, light[0]);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light[1]);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light[2]);

    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    glutSolidTeapot(100);

    glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y)
{
}

int main(int argc,char * argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE );
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(width,height);
    glutCreateWindow(*argv);
    createMenu(menuCallback, GLUT_LEFT_BUTTON, "Black Plastic", "Brass", "Bronze", "Chrome", "Copper", "Gold", "Peweter", "Silver", "Polished Silver", NULL);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    init();
    glutMainLoop();
    return 0;
}
  • 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-16T00:26:36+00:00Added an answer on June 16, 2026 at 12:26 am

    You’re drawing a solid teapot? I presume you enabled depth testing (though your glutInitDisplayMode lacks the depth buffer bit). Anyway, you should probably also clear the depth buffer. Right now you’re clearing only the color buffer

    glClear(GL_COLOR_BUFFER_BIT);
    

    Change it into

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that should execute a piece of code base on the
I have a program that's creating a secure directory for user output. This is
Problem: I want to write a process that will allow a user to take
Im trying to write a program that allow a user to track their DVDs.
This program should calculate the value of 2^1+2^2 + ... + 2^10: #include <stdio.h>
I am working on a bug in this program where it should be able
I have this program in Python which should save text files to a folder
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
I write a program to verify this website: www.alipay.com which root CA cert should
Dear all,Now i have this question in my java program,I think it should be

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.