I'm currently taking a Computer Graphics class at university, and have been given an assignment which involves loading an obj file and manipulating it with keyboard and mouse controls (eg. arrow keys translate, mouse wheel for zoom, hold mouse and drag for rotation).

Being new to OpenGL, I'm a bit overwhelmed by the project on hand, and would really appreciate if anyone could give me some tips regarding implementation of this project. Our previous (and first) project involved creating a clock based on system time, which was relatively straightforward, using simple rotation/translation techniques on OpenGL primitive objects created within the draw() function. I was able to easily figure out and understand this.

The main questions I have are:

  • Within the draw() function, how do I take the changes made by the keyboard/mouse and apply them to the object? More specifically, what exactly should be going on here in relation to the input methods?

    void Draw() 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
    // Write your own code below (Hint:Translation Rotation & Scaling)
    // Write your own code above
    if (obj_data != NULL)
        glutSolidTeapot(1.0);   //draw a teapot when no argument is provided
    // Write your own code below (Hint:reset translate and scale value)
    // Write your own code above


  • How does the mouseMotion() method work? More specifically, how might I go about getting the coordinates of the mouse location and use them within the program?

    void mouseMotion(int x, int y)
    //code here

I know this may be a vague and/or ambiguous question, but I really do not know where to start on this. My professor has not given much information as to how to implement this, and any pointers or tips that may guide me in the right direction would be incredibly appreciated!

Just so you know, I'm not posting this here for an easy answer so I can copy/paste. I'm mainly looking for a greater understanding of how OpenGL works, especially in relation to user input!

PS: The full source code for the project can be found here. There is also an objLoader.cpp file as well used to load a predrawn object into the workspace.

Let me know if more clarification is required. I've tried my best to consolidate this into smaller questions that might help me understand the project as a whole.

Thanks again!

  • $\begingroup$ You might find the Transformations, Coordinate Systems and Camera chapters of LearnOpenGL helpful. $\endgroup$
    – Maxpm
    Oct 8, 2018 at 7:45
  • $\begingroup$ Definately check out GFLW and ImGui (super easy GUI, speedy and small footprint). $\endgroup$
    – beyond
    Oct 8, 2018 at 12:55

2 Answers 2


OpenGL itself is purely a graphics library. It doesn't give you access to keyboard input.

However, if you're using OpenGL, you're also probably using a cross-platform context/window toolkit to create a desktop window and set up an OpenGL context for drawing into that window. These toolkits usually also give you basic keyboard and mouse input. (The idea is, I guess, if they're abstracting platform-specific window creation, they may as well abstract platform-specific window input at the same time.)

Your context toolkit looks to be FreeGLUT, so you should refer to the FreeGLUT documentation for details.


OpenGL is is a cross-language, cross-platform application programming interface (API), and it acts as a bridge between your CPU and your GPU.

It's not an input handling library, since that is something that is OS specific (on Windows for instance you would use DirectInput) and that has nothing to do with the GPU.

Now, as stated by the other answers, you are probably using a framework to handle context creation, setting up the pixelFormatDescriptor and creating the OS window (you would use the Win32 api on Windows), like Freeglut.

Freeglut at this point in time, is quite outdated (and probably not even supported anymore, i can't remember correctly). GLFW on the other hand, is a very well maintained and documented library for both input and window handling (that also includes context creation). In addition to that, the brand new Vulkan API is also avaiable for use. Input and Window handling is done through callbacks with a very intuitive API.

GLFW is written in C and licenced under the z-lib licence.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.