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

  • Home
  • SEARCH
  • 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 4623238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:57:29+00:00 2026-05-22T02:57:29+00:00

While passing material data to opengl (to be used in a shader): float white[4]

  • 0

While passing material data to opengl (to be used in a shader):


float white[4] ={1.0f,1.0f,1.0f,1.0f};

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, white);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);

int whitei[4] = {255,255,255,255};
glMaterialiv(GL_FRONT_AND_BACK, GL_AMBIENT, whitei);
glMaterialiv(GL_FRONT_AND_BACK, GL_DIFFUSE, whitei);
glMaterialiv(GL_FRONT_AND_BACK, GL_SPECULAR, whitei);

First one works beautifuly, but the second one only gives a black mesh. Both were used in the exact same context (basically I wrote the first one and then the second one replaced the first).

Does anyone have any idea why that is? glMaterialiv would really make my life easier (if I can get it to work) because I keep my colors as rgba bytes and I’m not sure if I want to make them 4 times bigger just to convert them to float.

  • 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-22T02:57:30+00:00Added an answer on May 22, 2026 at 2:57 am

    Both glColor3i and glMaterialiv take colors in the range [0, INT_MAX], with INT_MAX being 2^31 – 1. This explains your mesh being black, 255 is the equivalent of passing 0.000000119 for floats.

    Technically, passing it either as floats or ints shouldn’t matter much. In your example, you are already storing the individual components at 4 times their original size, so no loss there.

    I´m not even convinced passing skipping the int -> float conversion will yield any performance gain, as the driver might still convert things to float on the CPU side of things. I’m speculating there, testing would have to prove that.

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

Sidebar

Related Questions

What I want to do is while executing MySQL query, passing column data into
How can I instantiate an anonymous object while passing the propertynames and values as
I'm passing some numeric arguments while creating a process (in VC++) I'm stuck at
I tried passing a structure as the 4th argument while using pthread_create() with something
Earlier today I asked a question about passing dictionary values to a function. While
i am using rawurlencode($url_variable) while passing to a script.. when i receive the variable
I am working on a simple 2D soccer game, while passing the ball between
While using the org.apache.commons.lang.math.NumberUtils.isNumber(String str) function, I see that passing a string like 1f
I was wondering about the use of pthread_key_create while passing in a destructor function.
When I render a layout while passing it a block, for example: render(:layout =>

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.