Graphics Loader

Details
Role: Programmer
Duration: 9 Weeks
Team Size: 1
Tool: OpenGL [C++]
About
This project was developed during my studies at University of Staffordshire. I was tasked with creating a scene using computer graphics generated by OpenGL in C++. The graphics are loaded from files and then converted into programmable graphics to be placed within the scene.
Introduction
For this assignment, we had to shift our focus from curating a gameplay experience and
instead had to focus on how game graphics can be generated and managed manually. This was explored through using
OpenGL to create systems that manually built primitive shapes, whilst loading textures
and more complex shapes from file.
As the systems were all being built outside of an engine, all of the development was up to
me which gave me an opportunity to learn about memory management and using Visual
Studio to track where memory is being assigned. This could then be used to track issues
such as when memory leaks would appear and helped break down how the issue could be tackled.
OBJ File Loader


OBJ file model to computer-readable text conversion
This project uses file loading to assign values in a more concise manner for
primitive shapes, taking the values for vecrtices, indices and faces. This is a simple level
of file usage when used alongside primitivies, but this level of simplicity is not compatible
when using OBJ files.
To create my OBJ file loader, I found many sources leading me towards using text manipulation
to find all of the needed values and correctly assigning them to their variables through using
āfā for indices and āvā for vertices, furthermore subtracting the indices by 1
from all index readings from the file, as the file starts counting from 1 not 0. Using a C++
vector (also known as a list), we can store all the needed values as they are read to be
used later to build the object at runtime.
I found it difficult to understand how I could build the system from the ground up, alongside my
pre-established systems. After finding a tutorial that helped me understand and doing deeper
research into OpenGL and graphical programming as a whole, I was able to successfully create
the system that can be found below. My goal in the future is to make it more robust in order to
support a larger variety of OBJ files.
Code
- OBJ Loader
Scene Management
The management of the scene was the most worked on aspect throughout development. Starting at
manually drawing each primitive, to recycling data usage with files and then moving to
implementing arrays that were finialised as Linked Lists, with each linked list being used
to split scene objects into shape catorgories. Changing between these management styles
often called for iterative practices, revisting and reevaluating old code to work with the
updated mangement of the objects. While arrays aren't slow, I wanted to implement
dynamic changes to the lists at run time, such as changing individual values, or even
removing an object entirely. I am working on polishing the ability to remove
objects, yet the system is still used to dyanamically change the objects values at runtime.


Tools to manage and traverse the scene
I included a selection menu in this project, with the primitive objects inside a scene being able to be selected. When an object is selected, its texture will be swapped out as well as the camera becoming locked onto the selected texture. This is done so that the user can view the object from any angle by spinning the object in place, in any way they please. To improve the camera controls, I made the decision to split it into its own class to allow for more dynamic/realistic controls when moving around the scene. I came into conflict with this, as I had simply been moving the cameras eye and not its world position but in taking the time to understand the camera within graphics programming was the single most important learning experience of this project. It meant that I could begin to understand how a scene is actually generated, and how this is translated so that it can be viewed at runtime. In future I will implement a free-flying camera within graphics scenes, as currently the camera can only be moved in world space along a certain plane.
What was Learnt
While I have programmed a variety of programs throughout my studies and personal projects,
building this graphics scene was definitely one of the most challenging. This isn't a negative thing however
as this project was a chance to sit down and
truly understand systems that I only had a surface knowledge of before. I have always
strived for optimisation within my code, and having to manage memory and finding the sources of memory leaks as they occurred
were invaluable lessons in understanding my own coding and
how it can be used most effectively.
On the topic of graphics itself, I have a new found appreciation for the time and effort
needed for the graphics found in games today. I hope to build on my knowledge and
apperication as I progress ahead with my programming career and this project has helped me understand the time and
dedication needed to achieve the high quality results seen as the standard in modern games design.
Project Repository