Adding a Ground - OpenGL with PyOpenGL Python and PyGame - 7

sentdex · Beginner ·🛠️ AI Tools & Apps ·11y ago

Key Takeaways

This video tutorial covers adding a ground to a 3D game using OpenGL with PyOpenGL and PyGame, demonstrating how to create a flat plane as a ground surface and integrate it with existing cube objects.

Full Transcript

everybody what's going on welcome to the seventh PI OpenGL tutorial video in this video what we doing is I'm just going to show you guys how you could add a ground if you wanted so so like I was saying before one of the ways that we can stop a player from maybe going outside of the bounds that we're creating cubes is by having walls and one of those things would be maybe a ground you could really eliminate the idea of walls entirely and just create a single plane on the ground and eventually the plane has an edge and if the player goes over the edge they die and then you can take away the ability to move up and down and then we would put all the cubes on the ground and then you would just avoid the cubes still being 3d but you would just avoid the cubes moving like left or right so that's what I'm going to show you guys now it's how might we do that so first of all if you we can take this Y value change and for now let's just say it's zero and then we'll just comment out so under the set vertices function so now let's go ahead and save and run that just just to see where we are so you guys understand what we just did okay so now all the cubes basically come up right there now we're in theory kind of below these cubes so that's not ideal so instead of value change let's see was worth zero let's say if we put these two say a negative one let's try that like I thought that's where we were anyways okay so now they're like on level with us right and so in theory we could just add a ground and we could be like okay we're avoiding these cubes here okay so now let's go ahead and okay there and now it's good let's let's actually make a ground so how would we how would we make you know this floor well it sounds may be confusing but it's really not so if we think about how did we make the edge of the cube well we specified vertex vertex vertex vertex and we filled it in and that was it that's all you have to do so we can do the exact same thing for a ground so for example we can come here and we can say a ground this isn't totally necessary but we'll basically copy what we did for surfaces and edges I mean my there we go so what we could do is something like ground and in fact we're doing two ground surfaces actually we'll do ground vertices and ground vertices will equal a tuple and the tuple will be containing a bunch of tuples and for example we know that our X what our x and y well we want to have X&Y be first of all the ground we want it to be like slightly under so we'll say Y value change minus 1 let's make it a zero for now anyway or negative I'll have to test a few things I'm having trouble having trouble visualizing this but anyway you would have negative 10 to 10 on the X right the X should be negative 10 to 10 y should not change at all and then Z would be you know really far back in our case max distance basically so so what we could do is ground vertices a equals and then we would say negative negative 10 negative 0.1 just slightly under I think will work and then we don't want it to just be like really short so are really short rather so we want that ground to start at some point for now we'll just we'll have it start at the 20 and then let's just basically take this copy come down here paste now now this will be positive 10 right so these are the starting points and then now really deep we are going to have again the exact same because this is the ground so that's one two and then we got three and four and this would be negative ten and ten there and then instead of twenty let's do negative 300 and then negative 300 okay then what we need to do is we'll make a ground function so we'll define round it'll be empty parameters and then we'll just do a simple GL begin if you don't recall we use GL quads before to fill in and then we'll just say X actually let's do not like that so we're gonna say for vertex in ground underscore vertices oh my goodness I just want to spell misspell vs. as much as possible for vertex and ground vertices what do we want to do let's we can color it first so we'll do GL color three FV and then in here you put the color tuple so let's let's color it zero zero point five and then zero point five okay and just take note this is a tuple right it's a tuple as the parameter next we'll do GL vertex three FV and then the actual vertex okay then then we're all done GL end and that's it so now we've got ground and then basically we can just come down to our loop here and we'll draw the ground let's go ahead and draw the ground first so we don't have the ground being drawn over the cubes in the distance so we'll do ground and then we draw the cubes so let's go ahead and run that and see what happens okay so we have our ground there we're on the ground we see our cubes uh the ground definitely just this is really messing with me visually here but the ground definitely you can see it does have edges to it and stuff and we ran out of cubes with the ground is a little I think it was too high so we could lower the a little bit Stu negative will make this negative one actually let's make it negative one point one just do that let's come down on these though alright that's that's better so now that appears like we have a ground we do have an edge there and we can work with this and so you can use this to make you know the ground the walls and obviously we go above and below but it's just a little flat planes like right now we don't have any rules that stop us from doing anything but anyway you can imagine that you could add some rules there so while I don't intend to make this game and have walls or grounds or anything like that I did want to show like how you could do it so if you're making like a racing game you know you're gonna have a street and you're gonna have the car on the street and then you would you know have it going off into the distance or something and so that's how you could do that so anyways that's it for this video I just wanted to show real quick video how you could add a ground if you wanted I'm going to go ahead and not have a ground them and just copy their comment this out and then come down here and comment this one out and then finally come out the last one up at the top wherever it is I can't even find oh hey this is what we need to do yeah that should give us back a good starting position with random cubes right okay so anyways that's it for this video the next video will be continuing on and my idea of having infinite range so sticks you for that if you guys have any questions or comments on this video please feel free to leave them below otherwise as always thanks for watching

Original Description

In this OpenGL programming tutorial with Python and PyOpenGL we cover how to add a ground to our game if we want one. While we don't plan to continue along this thread, I wanted to show how it could be done before moving on. PyOpenGL playlist: http://youtu.be/R4n4NyDG2hI?list=PLQVvvaa0QuDdfGpqjkEJSeWKGCP31__wD PyGame with Python 3 Playlist: http://www.youtube.com/playlist?list=PLQVvvaa0QuDdLkP8MrOXLe_rKuf6r80KO Python: Python.org PyOpenGL: Either use http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl or http://pyopengl.sourceforge.net/ PyGame: Either use http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame or http://pygame.org/download.shtml sample code: http://pythonprogramming.net/opengl-pyopengl-python-pygame-tutorial/ http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video teaches how to add a ground plane to a 3D game using PyOpenGL and PyGame, covering vertex specification, color tuples, and integration with existing cube objects. The tutorial provides a step-by-step guide on creating a flat plane as a ground surface and demonstrates how to use OpenGL functions to render the ground plane.

Key Takeaways
  1. Specify vertex coordinates for the ground plane
  2. Define a color tuple for the ground plane
  3. Use GL_QUADS to render the ground plane
  4. Integrate the ground plane with existing cube objects
  5. Adjust vertex coordinates to position the ground plane correctly
  6. Use PyOpenGL and PyGame functions to render the 3D scene
💡 To create a 3D ground plane, you need to specify vertex coordinates, define a color tuple, and use OpenGL functions to render the plane, and then integrate it with existing cube objects to create a cohesive 3D scene.

Related Reads

📰
PodcastorAI Guide: How to Use It, Best Prompts & Use Cases (2026)
Learn to use PodcastorAI to turn scripts into studio-quality video podcast episodes in 15 minutes
Dev.to AI
📰
I built Steno to protect your most sensitive conversations. AI notetaker & notepad. 1200+ GitHub stars, 1000s of downloads
Learn about Steno, an AI-powered notetaker and notepad for sensitive conversations, and its latest release 0.6.4
Dev.to · Darth_Ruzin
📰
Enterprise Storage Is Rebuilding Itself Around AI-Ready Data
Enterprise storage is shifting focus from capacity to AI-ready data governance, driving 22.7% market growth in Q1 2026
Forbes Innovation
📰
Beyond 11,000: Navigating the Unified MCP Server Catalog That's Reshaping AI Tooling
Learn to navigate the Unified MCP Server Catalog with over 11,000 tools, reshaping AI tooling and streamlining development workflows
Dev.to · Robert Pelloni
Up next
Wix Harmony: Wix's AI Website Builder Explained (2026)
TheFigCo
Watch →