OpenGL Follow on

Sid Kraft 96 Reputation points
2026-07-23T22:23:25.1933333+00:00

Progressing with the OpenGL and producing a window to output graphics data, was told to enter the following but do not understand the data:

1.) glutInit (&arg1, arg2), arg1 integer, arg2 string

      was suggested on-line that if the values not needed can pass dummy variable? Not sure what these values represent

Please advise, Sid Kraft

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 84,856 Reputation points
    2026-07-24T03:18:43.8066667+00:00

    C/C++ is a low level language. This means you pass pointers. The & operator is used to pass the address of the pointer, rather than the pointer value. When used with value types like int and float the value is passed on the stack. If you use the & operator, then a pointer to the value is passed.

    in Fortran terms value types are passed by value, and the & operator means it’s a pass by reference (default for Fortran).

    For glutInit the function is defined as follows

    void glutInit(int *argcp, char **argv);
    
    • The first parameter is a pointer to int (pass by ref). it's typically a pointer to main(int argc). not sure why the api picked a pointer. It should be the count of entries in the argv array.
    • The second parameter is a pointer to a char pointer. the argv means vector so, its an array. It could be better written as char *args[], which is a pointer to array of char pointer (strings). This is because strings are defined as char*, that is a pointer to a character. 

    in C arrays are passed by reference (same as objects). as arrays don't have any meta data (size), an array variable is a pointer to the first location of the array. the array datatype gives the size of each element. so a variable that is an array of ints is int myarray[] (because it an array its a pointer) or can be specified as int *myarray which is a pointer to an int.

    #include <stdio.h>
    
    int main()
    {
        //define an array of ints
        int myArray[] = {0,1,2,3,4,5};
        int myArraySize = sizeof(myArray) / sizeof(myArray[0]); // must be computed at compile time
    
        // standard for loop of array
        for (int i=0; i < myArraySize; ++i) {
            printf("%d\n", myArray[i]);
        }
    
        printf("---------\n");
    
        // for pointer loop
        for (
           int *p1 = myArray; // pointer to array
           p1 < &myArray[myArraySize]; // pointer to last element
           ++p1 // inc pointer
        ) {
            printf("%d\n", *p1);
        }
    
        printf("---------\n");
    
        // more common while loop
        int *p1 = myArray; // pointer to array
        int *p2 = &myArray[myArraySize]; // pointer to last element + 1 (zero based array)
        while (p1 < p2) {
            printf("%d\n", *p1++);
        }
    }
    

    so you will need to understand address and pointer. you will see p->myprop to access the property of a class. the myprop is just an offset off pointer p.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Nancy Vo (WICLOUD CORPORATION) 8,070 Reputation points Microsoft External Staff Moderator
    2026-07-24T03:49:22.2966667+00:00

    Hello @Sid Kraft ,

    Thanks for your question.

    The glutInit function initializes the GLUT library. It expects the command-line arguments provided to your application.

    arg1: A pointer to an integer representing the number of command-line arguments.

    arg2: An array of strings representing the actual command-line arguments.

    While you can pass dummy variables, I recommend passing the arguments directly from your main function:

    int main(int argc, char** argv) {
        glutInit(&argc, argv);
        //  window creation
        return 0;
    }
    

    If you need to pass dummy variables because your main function does not have parameters, use this setup:

    int main() {
        int dummy_argc = 1;
        char* dummy_argv[1] = { (char*)"ProgramName" };
        glutInit(&dummy_argc, dummy_argv);
        return 0;
    }
    

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback. Thank you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.