Skip to content

laralex/PyOpenGL_Demos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenGL course for ISP (Skoltech)

OpenGL resources

I can't really suggest OpenGL books. Just beware that books older than 2010 may describe OpenGL 2, which is very obsolete and inefficient.

Computer graphics resources

Installation

We will be using a few Python libraries. Why? OpenGL only can manage GPU drawing (configuring GPU, sending/receiving data to GPU), it can't make windows and user interfaces in your operating system, it doesn't include mathematical primitives common in computer graphics, it's doesn't have anything for data parsing (e.g. 3D model files) and decoding (e.g. uncompressing JPEG or PNG images).

Thus, we'll use:

  • PyOpenGL (plus PyOpenGl_accelerate) - provides access to OpenGL API from Python
  • PyGLFW - manages cross-platform creation of windows (also available in C/C++ programming languages) and interation using keyboard/mouse
  • Pyrr - math functions commonly used in computer graphics
  • Imgui - fancy user-interface elements
  • Pillow - encoding and decoding image files
  • PyWavefront - decoding 3D models files in OBJ format

Option 1. (preferred) Anaconda environment:

conda create --name gl
conda activate gl
conda install -c conda-forge pyopengl-accelerate pyglfw pyrr pillow
pip install imgui[glfw] pywavefront

Option 2. If you don't mind polluting your default Python environment, then you can globally install like this:

pip install PyOpenGL PyOpenGL_accelerate glfw pyrr pillow imgui[glfw] pywavefront

!!!

You may have troubles when installing those packages.

How to use this repository

The most relevant version of the code is on the main branch of the repository. The repository contains:

  • Lecture demos
  • Homework demos, and those are implemented as "fill in the gaps" programs. Complete to see the demo!

This command should open a window with a running visualization, and UI controls that allow your interaction.

python run.py

If you're debugging one particular demo, it may be convenient to start the application with this demo right away.

python run.py hw1

If may also want to tweak the default UI parameters in a ui_defaults.json config of the particular demo folder.

How to work on homeworks

It might be challenging for some people to write their code and then try to get the latest updates from this repository. In order to preserve your own sanity, I suggest the following workflow:

  1. If you need to change files, create a separate git branch first
git branch my_branch
  1. Before writing your code, make sure you're on your branch (and not main branch).
git checkout my_branch
  1. Make your changes in the files, commit them whenever you like
git add myfile_1.py myfile_2.py
# or if you're confident:
git add --all 

# then
git commit -m "Message of my commit"
  1. Now suppose that you want to download the latest changes from this repository. Even while you're on you own branch my_branch, you should still be able to execute this, to get the latest updates
git fetch origin main:main

This will update content of the main branch, so your code is preserved. In order to combine updates and your own code, you better commit your changes as shown in item #3 of this list.

Next, execute this, while still being on my_branch

git merge main

This will attempt merging the code. If you're lucky and your code doesn't conflict with the updates, then the process will finish successfully. Otherwise you may see the message

CONFLICT (content): Merge conflict in

Automatic merge failed; fix conflicts and then commit the result.

This means, that you'll have to manually resolve the conflicts. This topic is quite complicated, so either:

After fixing the conflicts, there's a chance you've broken something. Try to launch the program to verify that no errors/exceptions are shown. If everything is OK, you need to continue merging

git merge --continue

You may be prompted to enter a commit message to finally finish the merge. And after that the updates should be added. Run the program again to double check that everything works.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published