Skip to content

Commit 4cd93fd

Browse files
all push
0 parents  commit 4cd93fd

File tree

6,353 files changed

+279705
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,353 files changed

+279705
-0
lines changed

Hello_openGL_Introduction.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from OpenGL.GL import *
2+
from OpenGL.GLUT import *
3+
from OpenGL.GLU import *
4+
5+
6+
def draw_points(x, y):
7+
glPointSize(100) #pixel size. by default 1 thake
8+
glBegin(GL_POINTS)
9+
glVertex2f(x,y) #jekhane show korbe pixel
10+
glEnd()
11+
12+
13+
def iterate():
14+
glViewport(0, 0, 500, 500)
15+
glMatrixMode(GL_PROJECTION)
16+
glLoadIdentity()
17+
glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
18+
glMatrixMode (GL_MODELVIEW)
19+
glLoadIdentity()
20+
21+
def showScreen():
22+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
23+
glLoadIdentity()
24+
iterate()
25+
glColor3f(0.0, 1.0, 0.0) #konokichur color set (RGB)
26+
#call the draw methods here
27+
draw_points(400, 300)
28+
glutSwapBuffers()
29+
30+
31+
32+
glutInit()
33+
#glutInitDisplayMode(GLUT_RGBA)
34+
glutInitWindowSize(1000, 1000) #window size
35+
#glutInitWindowPosition(100, 50)
36+
wind = glutCreateWindow(b"OpenGL Coding Practice") #window name
37+
glutDisplayFunc(showScreen)
38+
39+
glutMainLoop()

Introduction_2.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
from OpenGL.GL import *
2+
from OpenGL.GLUT import *
3+
from OpenGL.GLU import *
4+
5+
import math
6+
7+
W_Width, W_Height = 500,500
8+
9+
10+
ballx = bally = 0
11+
speed = 0.01
12+
ball_size = 2
13+
create_new = False
14+
15+
16+
class point:
17+
def __init__(self):
18+
self.x=0
19+
self.y=0
20+
self.z=0
21+
22+
23+
def crossProduct(a, b):
24+
result=point()
25+
result.x = a.y * b.z - a.z * b.y
26+
result.y = a.z * b.x - a.x * b.z
27+
result.z = a.x * b.y - a.y * b.x
28+
29+
return result
30+
31+
def convert_coordinate(x,y):
32+
global W_Width, W_Height
33+
a = x - (W_Width/2)
34+
b = (W_Height/2) - y
35+
return a,b
36+
37+
def draw_points(x, y, s):
38+
glPointSize(s) #pixel size. by default 1 thake
39+
glBegin(GL_POINTS)
40+
glVertex2f(x,y) #jekhane show korbe pixel
41+
glEnd()
42+
43+
def drawAxes():
44+
glLineWidth(1)
45+
glBegin(GL_LINES)
46+
glColor3f(1.0, 0.0, 0.0)
47+
glVertex2f(250,0)
48+
glVertex2f(-250,0)
49+
glColor3f(0.0, 0.0, 1.0)
50+
glVertex2f(0,250)
51+
glVertex2f(0,-250)
52+
glEnd()
53+
54+
glPointSize(5)
55+
glBegin(GL_POINTS)
56+
glColor3f(0, 1.0, 0.0)
57+
glVertex2f(0,0)
58+
59+
glEnd()
60+
61+
62+
def drawShapes():
63+
glBegin(GL_TRIANGLES)
64+
glVertex2d(-170,170)
65+
glColor3f(0, 1.0, 0.0)
66+
glVertex2d(-180,150)
67+
glColor3f(1,0, 0.0)
68+
glVertex2d(-160,150)
69+
glEnd()
70+
71+
glBegin(GL_QUADS)
72+
glVertex2d(-170,120)
73+
glColor3f(1,0, 1)
74+
glVertex2d(-150,120)
75+
glColor3f(0,0, 1)
76+
glVertex2d(-150,140)
77+
glColor3f(0,1,0)
78+
glVertex2d(-170,140)
79+
glEnd()
80+
81+
82+
def keyboardListener(key, x, y):
83+
84+
global ball_size
85+
if key==b'w':
86+
ball_size+=1
87+
print("Size Increased")
88+
if key==b's':
89+
ball_size-=1
90+
print("Size Decreased")
91+
# if key==b's':
92+
# print(3)
93+
# if key==b'd':
94+
# print(4)
95+
96+
glutPostRedisplay()
97+
98+
def specialKeyListener(key, x, y):
99+
global speed
100+
if key=='w':
101+
print(1)
102+
if key==GLUT_KEY_UP:
103+
speed *= 2
104+
print("Speed Increased")
105+
if key== GLUT_KEY_DOWN: #// up arrow key
106+
speed /= 2
107+
print("Speed Decreased")
108+
glutPostRedisplay()
109+
# if key==GLUT_KEY_RIGHT:
110+
111+
# if key==GLUT_KEY_LEFT:
112+
113+
114+
# if key==GLUT_KEY_PAGE_UP:
115+
116+
# if key==GLUT_KEY_PAGE_DOWN:
117+
118+
# case GLUT_KEY_INSERT:
119+
#
120+
#
121+
# case GLUT_KEY_HOME:
122+
#
123+
# case GLUT_KEY_END:
124+
#
125+
126+
127+
def mouseListener(button, state, x, y): #/#/x, y is the x-y of the screen (2D)
128+
global ballx, bally, create_new
129+
if button==GLUT_LEFT_BUTTON:
130+
if(state == GLUT_DOWN): # // 2 times?? in ONE click? -- solution is checking DOWN or UP
131+
print(x,y)
132+
c_X, c_y = convert_coordinate(x,y)
133+
ballx, bally = c_X, c_y
134+
135+
136+
if button==GLUT_RIGHT_BUTTON:
137+
if state == GLUT_DOWN:
138+
create_new = convert_coordinate(x,y)
139+
# case GLUT_MIDDLE_BUTTON:
140+
# //........
141+
142+
glutPostRedisplay()
143+
144+
145+
def display():
146+
#//clear the display
147+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
148+
glClearColor(0,0,0,0); #//color black
149+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
150+
#//load the correct matrix -- MODEL-VIEW matrix
151+
glMatrixMode(GL_MODELVIEW)
152+
#//initialize the matrix
153+
glLoadIdentity()
154+
#//now give three info
155+
#//1. where is the camera (viewer)?
156+
#//2. where is the camera looking?
157+
#//3. Which direction is the camera's UP direction?
158+
gluLookAt(0,0,200, 0,0,0, 0,1,0)
159+
glMatrixMode(GL_MODELVIEW)
160+
161+
drawAxes()
162+
global ballx, bally, ball_size
163+
draw_points(ballx, bally, ball_size)
164+
drawShapes()
165+
166+
glBegin(GL_LINES)
167+
glVertex2d(180,0)
168+
glVertex2d(180,180)
169+
glVertex2d(180,180)
170+
glVertex2d(0,180)
171+
glEnd()
172+
173+
if(create_new):
174+
m,n = create_new
175+
glBegin(GL_POINTS)
176+
glColor3f(0.7, 0.8, 0.6)
177+
glVertex2f(m,n)
178+
glEnd()
179+
180+
181+
glutSwapBuffers()
182+
183+
184+
def animate():
185+
#//codes for any changes in Models, Camera
186+
glutPostRedisplay()
187+
global ballx, bally,speed
188+
ballx=(ballx+speed)%180
189+
bally=(bally+speed)%180
190+
191+
def init():
192+
#//clear the screen
193+
glClearColor(0,0,0,0)
194+
#//load the PROJECTION matrix
195+
glMatrixMode(GL_PROJECTION)
196+
#//initialize the matrix
197+
glLoadIdentity()
198+
#//give PERSPECTIVE parameters
199+
gluPerspective(104, 1, 1, 1000.0)
200+
# **(important)**aspect ratio that determines the field of view in the X direction (horizontally). The bigger this angle is, the more you can see of the world - but at the same time, the objects you can see will become smaller.
201+
#//near distance
202+
#//far distance
203+
204+
205+
glutInit()
206+
glutInitWindowSize(W_Width, W_Height)
207+
glutInitWindowPosition(0, 0)
208+
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB) # //Depth, Double buffer, RGB color
209+
210+
# glutCreateWindow("My OpenGL Program")
211+
wind = glutCreateWindow(b"OpenGL Coding Practice")
212+
init()
213+
214+
glutDisplayFunc(display) #display callback function
215+
glutIdleFunc(animate) #what you want to do in the idle time (when no drawing is occuring)
216+
217+
glutKeyboardFunc(keyboardListener)
218+
glutSpecialFunc(specialKeyListener)
219+
glutMouseFunc(mouseListener)
220+
221+
glutMainLoop() #The main loop of OpenGL

OpenGL/AGL/__init__.py

Whitespace-only changes.

OpenGL/DISABLED/NVX/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""OpenGL Extensions"""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''OpenGL extension NVX.cross_process_interop
2+
3+
This module customises the behaviour of the
4+
OpenGL.raw.DISABLED.NVX.cross_process_interop to provide a more
5+
Python-friendly API
6+
7+
The official definition of this extension is available here:
8+
http://www.opengl.org/registry/specs/NVX/cross_process_interop.txt
9+
'''
10+
from OpenGL import platform, constant, arrays
11+
from OpenGL import extensions, wrapper
12+
import ctypes
13+
from OpenGL.raw.DISABLED import _types, _glgets
14+
from OpenGL.raw.DISABLED.NVX.cross_process_interop import *
15+
from OpenGL.raw.DISABLED.NVX.cross_process_interop import _EXTENSION_NAME
16+
17+
def glInitCrossProcessInteropNVX():
18+
'''Return boolean indicating whether this extension is available'''
19+
from OpenGL import extensions
20+
return extensions.hasGLExtension( _EXTENSION_NAME )
21+
22+
23+
### END AUTOGENERATED SECTION

OpenGL/DLLS/GLE_WIN32_README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This is a Win32 version of the GLE library
2+
compiled as a shared library (DLL) for use with
3+
e.g. Python's ctypes foreign-function interface.
4+
5+
To install, copy the file gle32.dll to your system32
6+
directory.

OpenGL/DLLS/freeglut32.vc10.dll

213 KB
Binary file not shown.

OpenGL/DLLS/freeglut32.vc14.dll

195 KB
Binary file not shown.

OpenGL/DLLS/freeglut32.vc9.dll

213 KB
Binary file not shown.

OpenGL/DLLS/freeglut64.vc10.dll

250 KB
Binary file not shown.

0 commit comments

Comments
 (0)