A simple window for learning OpenGL under Python

Source: Internet
Author: User

Recently watching an OpenGL tutorial: Https://learnopengl.com/Introduction, written in the easy-to-read, very good, and has a Chinese translation version: https://learnopengl-cn.github.io/

Try to re-implement the C + + code in the original tutorial with Python for a deeper learning effect

1. Operating system: Windows 10

2. Install python:https://www.python.org/downloads/, I use 3.6.3

3. Install Pyopengl: After you install Python, the PIP is installed by default, the PIP is added to the default path, and the Windows Command Line window enters pip install Pyopengl

4. Download GLFW: http://www.glfw.org/download.html download 32-bit Windows binaries, next to the compressed file extracted, get the library file Lib-vc2015/glfw3.dll

5. Download the GLFW python interface file: Download the glfw.py in HTTPS://GITHUB.COM/ROUGIER/PYGLFW and place it and the library file from the previous step in the Python default library directory or in the sibling directory of the current development code

6. Create the window.py file with the following code:

#!/usr/bin/env python#-*-coding:utf-8-*-Importsys, OSImportOpengl.gl as GLImportGlfwwin_width= 800Win_height= 600defframebuffer_size_callback (window, width, height): gl.glviewport (0, 0, width, height)defprocessinput (window):ifGlfw.glfwgetkey (window, GLFW. Glfw_key_escape) = =GLFW. GLFW_PRESS:glfw.glfwSetWindowShouldClose ()defMain (): Glfw.glfwinit () Glfw.glfwwindowhint (GLFW. Glfw_context_version_major,3) Glfw.glfwwindowhint (GLFW. Glfw_context_version_minor,3) Glfw.glfwwindowhint (GLFW. Glfw_opengl_profile, GLFW. glfw_opengl_core_profile) window= Glfw.glfwcreatewindow (Win_width, Win_height,"Learning OpenGL". Encode (), 0, 0)ifwindow = =0:Print("failed to create window") glfw.glfwterminate () glfw.glfwmakecontextcurrent (window) glfw.glfwsetframebuffersizecallback (window, FR Amebuffer_size_callback) while  notglfw.glfwwindowshouldclose (window): processinput (window) Gl.glclearcolor (0.2, 0.3, 0.3, 1.0) gl.glclear (gl.gl_color_buffer_bit) glfw.glfwswapbuffers (window) glfw.glfwpollevents () GLFW.GLFWT Erminate ()if __name__=="__main__": Main ()

The result of this code execution is as follows:

The above code is the Python implementation of the Hello Window chapter in the OpenGL tutorial, as shown in the original C + + code Https://learnopengl.com/Getting-started/Hello-Window

A simple window for learning OpenGL under Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.