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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:36:06+00:00 2026-05-27T12:36:06+00:00

I’m making a basic game in openGL with GLUT, and I’ve come across a

  • 0

I’m making a basic game in openGL with GLUT, and I’ve come across a small hitch.

When I attempt to draw an object from a class into my world, it gives everything a tint of colour which was last created with the function makeMaterial (see below).

Does anyone know how I could restrict these changes to being applied to the object only?
I’ve tried push/pop, but it doesn’t seem to limit anything.
Additionally, if the last colour drawn is black, I see nothing at all, except for my snowman.

Here are the relevant code:

makeMaterial :-

makeMaterial( float r,float g,float b,float a,float s )  
{   
    float color[4];  
    float white[4]; 
    GLfloat surfshine[1] ; 
    surfshine[0]=s*128.0 ; 
    color[0]=r;color[1]=g;color[2]=b;color[3]=a;  
    white[0]=0.5;white[1]=0.5;white[2]=0.5;white[3]=1.0;   
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,color);  
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,color);  
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,white); 
    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS,surfshine); 
} 

makeMaterial in use :-

makeMaterial(0.05f,0.05f,0.05f,1.00f, 0.4f);
glPushMatrix(); 
glutSolidCube(10.0); 
glPopMatrix(); 

my draw function :-

void drawToScene(void) {    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glLoadIdentity();   
    uniformFPS.setStartTime(glutGet(GLUT_ELAPSED_TIME));

    camera.updateCamera();
    lvl1.drawLevel();
    enemy.drawSnowman(350.0f,6.0f, 200.0f);
    crosshair.show();

    glutSwapBuffers();      
    uniformFPS.enforceChecks();
}
  • 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-05-27T12:36:06+00:00Added an answer on May 27, 2026 at 12:36 pm

    If you really want to ensure you are restricting changes to a specific section, you should be able to use glPushAttrib(GL_LIGHTING_BIT) before you do your makeMaterial call, and glPopAttrib after your drawing of the object is done. The reference for glPushAttrib here shows what properties are push’d by each of the possible bits you can supply. I don’t know that this is a particularly well regarded way to handle your state however.

    A more general solution would be to make a call to makeMaterial with appropriate values before each set of drawing commands, i.e. assuming you have just one material for your snowman and one material for your world:

    //...
    makeMaterial(1.0f,1.0f,1.0f,1.0f,1.0f);
    lvl1.drawLevel();
    makeMaterial(0.5f,0.5f,0.5f,0.5f,0.5f);
    enemy.drawSnowman(350.0f,6.0f,200.0f);
    //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I'm making a simple page using Google Maps API 3. My first. One marker

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.