├── FUNDING.yml ├── MeshRenderer.py ├── README.md ├── __pycache__ ├── MeshRenderer.cpython-37.pyc └── constants.cpython-37.pyc ├── constants.py └── main.py /FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: auctux 2 | ko_fi: auctux 3 | -------------------------------------------------------------------------------- /MeshRenderer.py: -------------------------------------------------------------------------------- 1 | from constants import * 2 | from OpenGL.GL import * 3 | from OpenGL.GLU import * 4 | 5 | def CubeMesh(): 6 | glBegin(GL_QUADS) 7 | for face in cube_faces_vector4: 8 | x = 0 9 | for vertex in face: 10 | x+=1 11 | glColor3fv(colors[x]) 12 | glVertex3fv(cube_verticies_vector3[vertex]) 13 | glEnd() 14 | 15 | glBegin(GL_LINES) 16 | for edge in cube_edges_vector2: 17 | for vertex in edge: 18 | glVertex3fv(cube_verticies_vector3[vertex]) 19 | glEnd() 20 | 21 | def ChairMesh(): 22 | glBegin(GL_QUADS) 23 | for face in chair_faces_vector4: 24 | x = 0 25 | for vertex in face: 26 | x+=1 27 | glColor3fv(colors[x]) 28 | glVertex3fv(chair_verticies_vector3[vertex]) 29 | glEnd() 30 | 31 | glBegin(GL_LINES) 32 | for edge in chair_edges_vector2: 33 | for vertex in edge: 34 | glVertex3fv(chair_verticies_vector3[vertex]) 35 | glEnd() 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 3D-Renderer-Graphics-with-python 2 | ## subscribe to my youtube channel : https://www.youtube.com/channel/UCjPk9YDheKst1FlAf_KSpyA 3 | you have to install: 4 | -pygame 5 | -PyopenGL 6 | ![3dpython (2)](https://user-images.githubusercontent.com/48150537/76984562-084b7e00-6965-11ea-977f-1d333c6c033e.png) 7 | -------------------------------------------------------------------------------- /__pycache__/MeshRenderer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/3D-Renderer-Graphics-with-python-/4bd00f7b16790ff6909fd22818e34fa11d26c24a/__pycache__/MeshRenderer.cpython-37.pyc -------------------------------------------------------------------------------- /__pycache__/constants.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/3D-Renderer-Graphics-with-python-/4bd00f7b16790ff6909fd22818e34fa11d26c24a/__pycache__/constants.cpython-37.pyc -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | cube_verticies_vector3 = ( 2 | (1.0000, 1.0000, 1.0000), 3 | (1.0000, 1.0000, -1.0000), 4 | (1.0000, -1.0000, 1.0000), 5 | (1.0000, -1.0000, -1.0000), 6 | (-1.0000, 1.0000, 1.0000), 7 | (-1.0000, 1.0000, -1.0000), 8 | (-1.0000, -1.0000, 1.0000), 9 | (-1.0000, -1.0000, -1.0000), 10 | ) 11 | colors = ( 12 | (1, 1, 1), 13 | (1, 0, 0), 14 | (1, 0, 1), 15 | (0, 1, 1), 16 | (1, 1, 1), 17 | (1, 1, 0), 18 | (1, 1, 1), 19 | (1, 0, 0), 20 | (1, 0, 1), 21 | (0, 1, 1), 22 | (1, 1, 1), 23 | (1, 1, 0), 24 | ) 25 | cube_edges_vector2 = ( 26 | (5, 7), 27 | (1, 5), 28 | (0, 1), 29 | (7, 6), 30 | (2, 3), 31 | (4, 5), 32 | (2, 6), 33 | (0, 2), 34 | (7, 3), 35 | (6, 4), 36 | (4, 0), 37 | (3, 1), 38 | ) 39 | 40 | cube_faces_vector4 = ( 41 | (0, 4, 6, 2), 42 | (3, 2, 6, 7), 43 | (7, 6, 4, 5), 44 | (5, 1, 3, 7), 45 | (1, 0, 2, 3), 46 | (5, 4, 0, 1) 47 | ) 48 | 49 | chair_verticies_vector3 = ( 50 | (-2.7454190254211426, -2.7454190254211426, -0.38944482803344727), 51 | (-2.7454190254211426, -2.7454190254211426, 0.38944482803344727), 52 | (-2.7454190254211426, 2.7454190254211426, -0.38944482803344727), 53 | (-2.7454190254211426, 2.7454190254211426, 0.38944482803344727), 54 | (2.7454190254211426, -2.7454190254211426, -0.38944482803344727), 55 | (2.7454190254211426, -2.7454190254211426, 0.38944482803344727), 56 | (2.7454190254211426, 2.7454190254211426, -0.38944482803344727), 57 | (2.7454190254211426, 2.7454190254211426, 0.38944482803344727), 58 | (-2.7454190254211426, 1.8302793502807617, -0.38944482803344727), 59 | (-2.7454190254211426, -1.8302793502807617, -0.38944482803344727), 60 | (-2.7454190254211426, -1.8302793502807617, 0.38944482803344727), 61 | (-2.7454190254211426, 1.8302793502807617, 0.38944482803344727), 62 | (2.7454190254211426, -1.8302793502807617, -0.38944482803344727), 63 | (2.7454190254211426, 1.8302793502807617, -0.38944482803344727), 64 | (2.7454190254211426, 1.8302793502807617, 0.38944482803344727), 65 | (2.7454190254211426, -1.8302793502807617, 0.38944482803344727), 66 | (1.8302793502807617, 2.7454190254211426, -0.38944482803344727), 67 | (-1.8302793502807617, 2.7454190254211426, -0.38944482803344727), 68 | (-1.8302793502807617, 2.7454190254211426, 0.38944482803344727), 69 | (1.8302793502807617, 2.7454190254211426, 0.38944482803344727), 70 | (-1.8302793502807617, -2.7454190254211426, -0.38944482803344727), 71 | (1.8302793502807617, -2.7454190254211426, -0.38944482803344727), 72 | (1.8302793502807617, -2.7454190254211426, 0.38944482803344727), 73 | (-1.8302793502807617, -2.7454190254211426, 0.38944482803344727), 74 | (-1.8302793502807617, 1.8302793502807617, 0.38944482803344727), 75 | (1.8302793502807617, 1.8302793502807617, 0.38944482803344727), 76 | (-1.8302793502807617, -1.8302793502807617, 0.38944482803344727), 77 | (1.8302793502807617, -1.8302793502807617, 0.38944482803344727), 78 | (1.8302793502807617, 1.8302793502807617, -0.38944482803344727), 79 | (-1.8302793502807617, 1.8302793502807617, -0.38944482803344727), 80 | (1.8302793502807617, -1.8302793502807617, -0.38944482803344727), 81 | (-1.8302793502807617, -1.8302793502807617, -0.38944482803344727), 82 | (-2.7454190254211426, -1.8302793502807617, -5.67388391494751), 83 | (-2.7454190254211426, -2.7454190254211426, -5.67388391494751), 84 | (-1.8302793502807617, 2.7454190254211426, -5.67388391494751), 85 | (-2.7454190254211426, 2.7454190254211426, -5.67388391494751), 86 | (2.7454190254211426, 1.8302793502807617, -5.67388391494751), 87 | (2.7454190254211426, 2.7454190254211426, -5.67388391494751), 88 | (1.8302793502807617, -2.7454190254211426, -5.67388391494751), 89 | (2.7454190254211426, -2.7454190254211426, -5.67388391494751), 90 | (-2.7454190254211426, 1.8302793502807617, -5.67388391494751), 91 | (2.7454190254211426, -1.8302793502807617, -5.67388391494751), 92 | (-1.8302793502807617, 1.8302793502807617, -5.67388391494751), 93 | (-1.8302793502807617, -1.8302793502807617, -5.67388391494751), 94 | (1.8302793502807617, 2.7454190254211426, -5.67388391494751), 95 | (-1.8302793502807617, -2.7454190254211426, -5.67388391494751), 96 | (1.8302793502807617, 1.8302793502807617, -5.67388391494751), 97 | (1.8302793502807617, -1.8302793502807617, -5.67388391494751), 98 | (-2.7454190254211426, 1.8302793502807617, 6.973661422729492), 99 | (-2.7454190254211426, 2.7454190254211426, 6.973661422729492), 100 | (1.8302793502807617, 2.7454190254211426, 6.973661422729492), 101 | (2.7454190254211426, 2.7454190254211426, 6.973661422729492), 102 | (2.7454190254211426, 1.8302793502807617, 6.973661422729492), 103 | (1.8302793502807617, 1.8302793502807617, 6.973661422729492), 104 | (-1.8302793502807617, 2.7454190254211426, 6.973661422729492), 105 | (-1.8302793502807617, 1.8302793502807617, 6.973661422729492), 106 | (-2.7454190254211426, 1.8302793502807617, 2.584183692932129), 107 | (-2.7454190254211426, 1.8302793502807617, 4.7789225578308105), 108 | (-2.7454190254211426, 2.7454190254211426, 4.7789225578308105), 109 | (-2.7454190254211426, 2.7454190254211426, 2.584183692932129), 110 | (-1.8302793502807617, 2.7454190254211426, 2.584183692932129), 111 | (-1.8302793502807617, 2.7454190254211426, 4.7789225578308105), 112 | (-1.8302793502807617, 1.8302793502807617, 4.7789225578308105), 113 | (-1.8302793502807617, 1.8302793502807617, 2.584183692932129), 114 | (2.7454190254211426, 1.8302793502807617, 2.584183692932129), 115 | (2.7454190254211426, 1.8302793502807617, 4.7789225578308105), 116 | (1.8302793502807617, 1.8302793502807617, 4.7789225578308105), 117 | (1.8302793502807617, 1.8302793502807617, 2.584183692932129), 118 | (2.7454190254211426, 2.7454190254211426, 2.584183692932129), 119 | (2.7454190254211426, 2.7454190254211426, 4.7789225578308105), 120 | (1.8302793502807617, 2.7454190254211426, 2.584183692932129), 121 | (1.8302793502807617, 2.7454190254211426, 4.7789225578308105), 122 | (-2.7454190254211426, 1.8302793502807617, 5.8762922286987305), 123 | (-1.8302793502807617, 2.7454190254211426, 5.8762922286987305), 124 | (-2.7454190254211426, 2.7454190254211426, 5.8762922286987305), 125 | (-1.8302793502807617, 1.8302793502807617, 5.8762922286987305), 126 | (-2.7454190254211426, 1.8302793502807617, 3.6815531253814697), 127 | (-2.7454190254211426, 2.7454190254211426, 3.6815531253814697), 128 | (-1.8302793502807617, 2.7454190254211426, 3.6815531253814697), 129 | (-1.8302793502807617, 1.8302793502807617, 3.6815531253814697), 130 | (2.7454190254211426, 1.8302793502807617, 3.6815531253814697), 131 | (1.8302793502807617, 1.8302793502807617, 3.6815531253814697), 132 | (2.7454190254211426, 2.7454190254211426, 3.6815531253814697), 133 | (1.8302793502807617, 2.7454190254211426, 3.6815531253814697), 134 | (2.7454190254211426, 1.8302793502807617, 5.8762922286987305), 135 | (2.7454190254211426, 2.7454190254211426, 5.8762922286987305), 136 | (1.8302793502807617, 2.7454190254211426, 5.8762922286987305), 137 | (1.8302793502807617, 1.8302793502807617, 5.8762922286987305), 138 | (0.0, 2.0354409217834473, 5.630277156829834), 139 | (0.0, 2.0354409217834473, 5.024937629699707), 140 | (0.0, 2.540257453918457, 5.024937629699707), 141 | (0.0, 2.540257453918457, 5.630277156829834), 142 | (0.0, 2.0326993465423584, 3.4388256072998047), 143 | (0.0, 2.0326993465423584, 2.826911211013794), 144 | (0.0, 2.542999029159546, 2.826911211013794), 145 | (0.0, 2.542999029159546, 3.4388256072998047), 146 | ) 147 | chair_edges_vector2 = ( 148 | (9, 0), 149 | (0, 1), 150 | (11, 3), 151 | (3, 2), 152 | (17, 2), 153 | (19, 7), 154 | (7, 6), 155 | (13, 6), 156 | (15, 5), 157 | (5, 4), 158 | (21, 4), 159 | (23, 1), 160 | (2, 8), 161 | (8, 9), 162 | (1, 10), 163 | (10, 11), 164 | (4, 12), 165 | (12, 13), 166 | (7, 14), 167 | (14, 15), 168 | (25, 14), 169 | (27, 15), 170 | (29, 8), 171 | (31, 9), 172 | (14, 13), 173 | (15, 12), 174 | (10, 9), 175 | (11, 8), 176 | (6, 16), 177 | (16, 17), 178 | (3, 18), 179 | (18, 19), 180 | (0, 20), 181 | (20, 21), 182 | (5, 22), 183 | (22, 23), 184 | (11, 24), 185 | (24, 25), 186 | (10, 26), 187 | (26, 27), 188 | (13, 28), 189 | (28, 29), 190 | (12, 30), 191 | (30, 31), 192 | (29, 31), 193 | (28, 30), 194 | (17, 29), 195 | (16, 28), 196 | (25, 27), 197 | (24, 26), 198 | (19, 25), 199 | (18, 24), 200 | (27, 22), 201 | (26, 23), 202 | (31, 20), 203 | (30, 21), 204 | (22, 21), 205 | (23, 20), 206 | (18, 17), 207 | (19, 16), 208 | (32, 33), 209 | (34, 35), 210 | (36, 37), 211 | (38, 39), 212 | (35, 40), 213 | (39, 41), 214 | (42, 40), 215 | (43, 32), 216 | (37, 44), 217 | (33, 45), 218 | (36, 46), 219 | (41, 47), 220 | (34, 42), 221 | (44, 46), 222 | (43, 45), 223 | (47, 38), 224 | (2, 35), 225 | (40, 8), 226 | (12, 41), 227 | (47, 30), 228 | (6, 37), 229 | (44, 16), 230 | (13, 36), 231 | (42, 29), 232 | (9, 32), 233 | (33, 0), 234 | (31, 43), 235 | (4, 39), 236 | (34, 17), 237 | (20, 45), 238 | (46, 28), 239 | (21, 38), 240 | (48, 49), 241 | (50, 51), 242 | (51, 52), 243 | (53, 52), 244 | (49, 54), 245 | (48, 55), 246 | (50, 53), 247 | (54, 55), 248 | (72, 48), 249 | (59, 3), 250 | (84, 52), 251 | (67, 25), 252 | (73, 54), 253 | (63, 24), 254 | (85, 51), 255 | (86, 50), 256 | (11, 56), 257 | (76, 57), 258 | (74, 58), 259 | (77, 59), 260 | (18, 60), 261 | (78, 61), 262 | (75, 62), 263 | (79, 63), 264 | (59, 60), 265 | (58, 61), 266 | (63, 56), 267 | (62, 57), 268 | (60, 63), 269 | (61, 62), 270 | (56, 59), 271 | (57, 58), 272 | (14, 64), 273 | (80, 65), 274 | (87, 66), 275 | (81, 67), 276 | (7, 68), 277 | (82, 69), 278 | (19, 70), 279 | (83, 71), 280 | (67, 70), 281 | (66, 71), 282 | (70, 68), 283 | (71, 69), 284 | (68, 64), 285 | (69, 65), 286 | (64, 67), 287 | (65, 66), 288 | (57, 72), 289 | (61, 73), 290 | (49, 74), 291 | (55, 75), 292 | (74, 73), 293 | (75, 72), 294 | (73, 75), 295 | (72, 74), 296 | (56, 76), 297 | (58, 77), 298 | (60, 78), 299 | (62, 79), 300 | (76, 77), 301 | (78, 79), 302 | (79, 76), 303 | (77, 78), 304 | (64, 80), 305 | (66, 81), 306 | (68, 82), 307 | (70, 83), 308 | (80, 81), 309 | (82, 80), 310 | (83, 82), 311 | (81, 83), 312 | (65, 84), 313 | (69, 85), 314 | (71, 86), 315 | (53, 87), 316 | (87, 86), 317 | (86, 85), 318 | (85, 84), 319 | (84, 87), 320 | (88, 89), 321 | (90, 89), 322 | (90, 91), 323 | (91, 88), 324 | (89, 66), 325 | (61, 90), 326 | (89, 62), 327 | (73, 91), 328 | (86, 91), 329 | (75, 88), 330 | (71, 90), 331 | (87, 88), 332 | (92, 93), 333 | (94, 93), 334 | (94, 95), 335 | (95, 92), 336 | (67, 93), 337 | (83, 95), 338 | (78, 95), 339 | (94, 60), 340 | (63, 93), 341 | (92, 79), 342 | (94, 70), 343 | (92, 81), 344 | ) 345 | chair_faces_vector4 = ( 346 | (8, 11, 3, 2, ), 347 | (16, 19, 7, 6, ), 348 | (12, 15, 5, 4, ), 349 | (20, 23, 1, 0, ), 350 | (6, 13, 36, 37, ), 351 | (26, 10, 1, 23, ), 352 | (87, 84, 52, 53, ), 353 | (24, 11, 10, 26, ), 354 | (16, 6, 37, 44, ), 355 | (28, 13, 12, 30), 356 | (6, 7, 14, 13), 357 | (13, 14, 15, 12), 358 | (0, 1, 10, 9 ), 359 | (9, 10, 11, 8, ), 360 | (8, 29, 31, 9, ), 361 | (29, 28, 30, 31), 362 | (30, 12, 41, 47), 363 | (17, 16, 28, 29), 364 | (14, 25, 27, 15), 365 | (25, 24, 26, 27), 366 | (74, 72, 48, 49), 367 | (19, 18, 24, 25), 368 | (15, 27, 22, 5), 369 | (27, 26, 23, 22), 370 | (8, 2, 35, 40), 371 | (31, 30, 21, 20), 372 | (4, 5, 22, 21), 373 | (21, 22, 23, 20), 374 | (2, 3, 18, 17), 375 | (17, 18, 19, 16), 376 | (47, 41, 39, 38), 377 | (44, 37, 36, 46), 378 | (35, 34, 42, 40), 379 | (32, 43, 45, 33), 380 | (29, 8, 40, 42), 381 | (0, 9, 32, 33), 382 | (9, 31, 43, 32), 383 | (12, 4, 39, 41), 384 | (17, 29, 42, 34 ), 385 | (31, 20, 45, 43 ), 386 | (20, 0, 33, 45 ), 387 | (28, 16, 44, 46 ), 388 | (4, 21, 38, 39), 389 | (13, 28, 46, 36 ), 390 | (21, 30, 47, 38, ), 391 | (2, 17, 34, 35, ), 392 | (54, 49, 48, 55, ), 393 | (51, 50, 53, 52, ), 394 | (75, 73, 54, 55, ), 395 | (84, 85, 51, 52, ), 396 | (85, 86, 50, 51, ), 397 | (72, 75, 55, 48, ), 398 | (73, 74, 49, 54, ), 399 | (86, 87, 53, 50, ), 400 | (18, 3, 59, 60, ), 401 | (78, 77, 58, 61, ), 402 | (11, 24, 63, 56, ), 403 | (76, 79, 62, 57, ), 404 | (24, 18, 60, 63, ), 405 | (79, 78, 61, 62, ), 406 | (3, 11, 56, 59, ), 407 | (77, 76, 57, 58, ), 408 | (19, 25, 67, 70, ), 409 | (83, 81, 66, 71, ), 410 | (7, 19, 70, 68, ), 411 | (82, 83, 71, 69, ), 412 | (14, 7, 68, 64, ), 413 | (80, 82, 69, 65, ), 414 | (25, 14, 64, 67, ), 415 | (81, 80, 65, 66, ), 416 | (61, 58, 74, 73, ), 417 | (57, 62, 75, 72, ), 418 | (61, 73, 91, 90, ), 419 | (58, 57, 72, 74, ), 420 | (59, 56, 76, 77, ), 421 | (81, 83, 95, 92, ), 422 | (56, 63, 79, 76, ), 423 | (60, 59, 77, 78, ), 424 | (67, 64, 80, 81, ), 425 | (64, 68, 82, 80, ), 426 | (68, 70, 83, 82, ), 427 | (70, 67, 93, 94, ), 428 | (62, 61, 90, 89, ), 429 | (69, 71, 86, 85, ), 430 | (65, 69, 85, 84, ), 431 | (66, 65, 84, 87, ), 432 | (89, 90, 91, 88, ), 433 | (66, 87, 88, 89, ), 434 | (87, 86, 91, 88, ), 435 | (73, 75, 88, 91, ), 436 | (86, 71, 90, 91, ), 437 | (71, 66, 89, 90, ), 438 | (75, 62, 89, 88, ), 439 | (93, 94, 95, 92, ), 440 | (60, 78, 95, 94, ), 441 | (83, 70, 94, 95, ), 442 | (79, 63, 93, 92, ), 443 | (78, 79, 92, 95, ), 444 | (63, 60, 94, 93, ), 445 | (67, 81, 92, 93, ), 446 | ) 447 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from OpenGL.GL import * 2 | from OpenGL.GLU import * 3 | 4 | import random 5 | import pygame 6 | import os 7 | 8 | from pygame.locals import * 9 | from constants import * 10 | from MeshRenderer import CubeMesh, ChairMesh 11 | 12 | os.environ["SDL_VIDEO_CENTERED"]='1' 13 | 14 | 15 | def random_color(): 16 | x = random.randint(0, 255) / 255 17 | y = random.randint(0, 255) / 255 18 | z = random.randint(0, 255) / 255 19 | color = (x, y, z) 20 | return color 21 | 22 | colors_list= [] 23 | 24 | for n in range(len(chair_faces_vector4)): 25 | colors_list.append(random_color()) 26 | 27 | 28 | def main(): 29 | pygame.init() 30 | display = (1000, 1080) 31 | pygame.display.set_mode(display, DOUBLEBUF|OPENGL) 32 | 33 | gluPerspective(45, (display[0]/display[1]), 0.1, 50.0) 34 | glTranslatef(0.0, 0.0, -20) 35 | glRotatef(-90, 2, 0, 0) 36 | 37 | 38 | main() 39 | run = True 40 | while run: 41 | for event in pygame.event.get(): 42 | if event.type == pygame.QUIT: 43 | run = False 44 | glRotatef(4, 3, -10, -45) 45 | 46 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 47 | ChairMesh() 48 | pygame.display.flip() 49 | pygame.time.wait(10) 50 | pygame.quit() 51 | quit() 52 | --------------------------------------------------------------------------------