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

The Archive Base Latest Questions

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

I was studying some OpenGL codes and I found the Mesa code for the

  • 0

I was studying some OpenGL codes and I found the Mesa code for the gluPickMatrix function:

void gluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, 
GLint viewport[4])
{
 GLfloat m[16];
 GLfloat sx, sy;
 GLfloat tx, ty;

 sx = viewport[2] / width;
 sy = viewport[3] / height;
 tx = (viewport[2] + 2.0 * (viewport[0] - x)) / width;
 ty = (viewport[3] + 2.0 * (viewport[1] - y)) / height;

 #define M(row, col) m[col*4+row]
  M(0, 0) = sx;
  M(0, 1) = 0.0;
  M(0, 2) = 0.0;
  M(0, 3) = tx;
  M(1, 0) = 0.0;
  M(1, 1) = sy;
  M(1, 2) = 0.0;
  M(1, 3) = ty;
  M(2, 0) = 0.0;
  M(2, 1) = 0.0;
  M(2, 2) = 1.0;
  M(2, 3) = 0.0;
  M(3, 0) = 0.0;
  M(3, 1) = 0.0;
  M(3, 2) = 0.0;
  M(3, 3) = 1.0;
 #undef M

 glMultMatrixf(m);
}

My doubt in this case is with the M macro and the ‘col*4+row’ operation. This equation, as I understand, is to obtain the indexes of the pick matrix and then assign them values.

Is this macro a better approach than simply using m[0] = something?

Is it faster? or more efficient?

  • 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-27T20:27:07+00:00Added an answer on May 27, 2026 at 8:27 pm

    It’s not faster in any way, the compiler will see the expanded code (the preprocessor expands the macros before the compiler gets at it).

    It’s just a convenience to save typing few characters, and make the code more readable – hardcoding the equivalent constants would be much less clear.

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

Sidebar

Related Questions

I'm studying some code examples that I haven't written myself, and I found this
I am studying some scala code and found this method which baffles me. In
I was studying some code I found on the web recently, and came across
I'm in the middle in studying some code and I encountered this word "Append"
I began studying Java Regular Expression recently and I found some really intersting task.For
I'm studying object literals and self-executing functions in Javascript. Looking through some YUI code
I was studying Perlin's Noise through some examples @ http://dindinx.net/OpenGL/index.php?menu=exemples&submenu=shaders and couldn't help to
Im studying some ruby code and I see this varx variable being used with
I'm studying some Rails 3 code from Spree: module Spree module Generators class SiteGenerator
All, I am studying some sample code given in my web dev class as

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.