- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 glDrawArray 上修改程序。如果我只使用
glVertex3f一切都很好,如果我使用
glDrawArrays`作为相同的顶点值,除了图形之外,我还会得到一些随机线。
50% 时我收到错误
pgl.glDrawArrays(pgl.GL_TRIANGLE_STRIP, 0, array_size)
OSError: exception: access violation reading 0x0CF52000
import pyglet
import pyglet.gl as pgl
from pyglet.window import key
import math
import json
import time
win = pyglet.window.Window(1300, 1000, resizable=True)
global_time = time.time()
frame_counter = 0
WINDOW = 1000
tr = 96
tr_temp = 90
INCREMENT = 5
transparant = False
xRotation = -70
zRotation = -30
yRotation = 180
zoom = 1
x = -180
y = 70
z = 0
light = False
param = 0
t_prev = -5
start_loop = False
run_l = False
Texture = False
texture_obj = None
lamp1 = False
lamp2 = False
lamp3 = False
data = {}
with open('PycharmProjects/untitled/data.json') as fp:
data = json.load(fp)
transparant = data['transparant']
xRotation = data['xRotation']
yRotation = data['yRotation']
zRotation = data['zRotation']
zoom = data['zoom']
x = data['x']
y = data['y']
z = data['z']
light = data['light']
param = data['param']
t_prev = data['t_prev']
start_loop = data['start_loop']
run_l = data['run_l']
Texture = data['Texture']
lamp1 = data['lamp1']
lamp2 = data['lamp2']
lamp3 = data['lamp3']
tr = data['tr']
def writeToJSONFile(path, filename, data):
filePathName = path + '.json'
with open(filePathName, 'w') as fp:
json.dump(data,fp)
def run_loop(dt):
on_draw()
def draw_figure():
global texture_obj
angle = 0
t = 0
x = y = z = 0
a = 50
b = 100
array_size = 0
array = []
if Texture:
if texture_obj == None:
texture_obj = pyglet.image.load("PycharmProjects/untitled/test1_texture.bmp").get_texture()
pgl.glBindTexture(pgl.GL_TEXTURE_2D, texture_obj.id)
pgl.glEnable(pgl.GL_TEXTURE_2D)
# pgl.glTexParameterf(pgl.GL_TEXTURE_2D, pgl.GL_TEXTURE_WRAP_T, pgl.GL_REPEAT)
# pgl.glTexParameterf(pgl.GL_TEXTURE_2D, pgl.GL_TEXTURE_MAG_FILTER, pgl.GL_NEAREST)
# #
#
# pgl.glTexEnvi(pgl.GL_TEXTURE_ENV, pgl.GL_TEXTURE_ENV_MODE, pgl.GL_REPLACE)
else:
pgl.glDisable(pgl.GL_TEXTURE_2D)
if not transparant:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
else:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE)
pgl.glBegin(pgl.GL_TRIANGLE_STRIP)
for i in range(0, tr + 1):
pgl.glColor3ub(0, 0, 0)
if i >= 1:
t1 = a1
t2 = a2
t3 = a3
u = math.cos(i * 2 * math.pi / tr)
v = math.sin(i * 2 * math.pi / tr)
a1 = x + a * u
a2 = y + b * v
a3 = z + 8
if Texture:
pgl.glTexCoord2f(u * 0.5 + 0.5, v * 0.5 + 0.5)
pgl.glVertex3f(a1, a2, a3)
if i >= 1:
pgl.glNormal3f((b2 - t2) * (a3 - b3) - (b3 - t3) * (a2 - b2), (b3 - t3) * (a1 - b1) - (b1 - t1) * (a3 - b3),
(b1 - t1) * (a2 - b2) - (b2 - t2) * (a1 - b1))
b1 = x
b2 = y
b3 = z + 8
if Texture:
pgl.glTexCoord2f(0.5, 0.5)
pgl.glVertex3f(b1, b2, b3)
pgl.glEnd()
for j in range(1, 27):
pgl.glBegin(pgl.GL_TRIANGLE_STRIP)
pgl.glColor3ub(0, 0, 0)
x1 = a * math.cos(0)
y1 = b * math.sin(0)
a1 = x1 * math.cos(t * math.pi / 360) + y1 * math.sin(t * math.pi / 360)
a2 = - x1 * math.sin(t * math.pi / 360) + y1 * math.cos(t * math.pi / 360)
a3 = z + j * 8
if Texture:
pgl.glTexCoord2f(0.0, 0.0)
a01 = a1
a02 = a2
a03 = a3
print(a1,a2,a3)
array.extend([a1,a2,a3])
array_size += 3
# pgl.glVertex3f(a1, a2, a3)
b1 = x1 * math.cos((t + 16) * math.pi / 360) + y1 * math.sin((t + 16) * math.pi / 360)
b2 = - x1 * math.sin((t + 16) * math.pi / 360) + y1 * math.cos((t + 16) * math.pi / 360)
b3 = z + j * 8 + 8
u = math.cos((t + 16) * math.pi / 360) + math.sin((t + 16) * math.pi / 360)
v = (j - 1) / 26
if Texture:
pgl.glTexCoord2f(0.0, 0.0)
array.extend([b1,b2,b3])
print(b1,b2,b3)
array_size += 3
# pgl.glVertex3f(b1, b2, b3)
b01 = b1
b02 = b2
b03 = b3
for i in range(1, tr):
pgl.glColor3ub(0, 0, 0)
x1 = a * math.cos(i * 2 * math.pi / tr)
y1 = b * math.sin(i * 2 * math.pi / tr)
t1 = a1
t2 = a2
t3 = a3
a1 = x1 * math.cos(t * math.pi / 360) + y1 * math.sin(t * math.pi / 360)
a2 = - x1 * math.sin(t * math.pi / 360) + y1 * math.cos(t * math.pi / 360)
a3 = z + j * 8
pgl.glNormal3f((b2 - t2) * (a3 - b3) - (b3 - t3) * (a2 - b2), (b3 - t3) * (a1 - b1) - (b1 - t1) * (a3 - b3),
(b1 - t1) * (a2 - b2) - (b2 - t2) * (a1 - b1))
v = math.cos(t * math.pi / 360) + math.sin(t * math.pi / 360)
if Texture:
pgl.glTexCoord2f((i - 1) / tr, (26 - j) / 26)
array.extend([a1,a2,a3])
print(a1,a2,a3)
array_size += 3
# pgl.glVertex3f(a1, a2, a3)
x1 = a * math.cos(i * 2 * math.pi / tr)
y1 = b * math.sin(i * 2 * math.pi / tr)
b1 = x1 * math.cos((t + 16) * math.pi / 360) + y1 * math.sin((t + 16) * math.pi / 360)
b2 = - x1 * math.sin((t + 16) * math.pi / 360) + y1 * math.cos((t + 16) * math.pi / 360)
b3 = z + j * 8 + 8
v = math.cos((t + 16) * math.pi / 360) + math.sin((t + 16) * math.pi / 360)
if Texture:
pgl.glTexCoord2f((i - 1) / tr, (25 - j) / 26)
array.extend([b1,b2,b3])
print(b1,b2,b3)
array_size += 3
# pgl.glVertex3f(b1, b2, b3)
print(a01,a02,a03)
array.extend([a01,a02,a03])
array_size += 3
# pgl.glVertex3f(a01, a02, a03)
print(b01,b02,b03)
array.extend([b01,b02,b03])
array_size += 3
# pgl.glVertex3f(b01, b02, b03)
t = t + 16
pgl.glEnd()
pgl.glBegin(pgl.GL_TRIANGLE_STRIP)
t = 416
z = z + 144
angle = angle + t
for i in range(0, tr + 1):
pgl.glColor3ub(0, 0, 0)
u = math.cos(i * 2 * math.pi / tr)
v = math.sin(i * 2 * math.pi / tr)
x1 = x + a * u
y1 = y + b * v
x2 = x1 * math.cos(t * math.pi / 360) + y1 * math.sin(t * math.pi / 360)
y2 = - x1 * math.sin(t * math.pi / 360) + y1 * math.cos(t * math.pi / 360)
if i >= 1:
t1 = a1
t2 = a2
t3 = a3
a1 = x2
a2 = y2
a3 = z + 72
if Texture:
pgl.glTexCoord2f(u * 0.5 + 0.5, v * 0.5 + 0.5)
pgl.glVertex3f(a1, a2, a3)
if i >= 1:
pgl.glNormal3f((b2 - t2) * (a3 - b3) - (b3 - t3) * (a2 - b2), (b3 - t3) * (a1 - b1) - (b1 - t1) * (a3 - b3),
(b1 - t1) * (a2 - b2) - (b2 - t2) * (a1 - b1))
b1 = x
b2 = y
b3 = z + 72
if Texture:
pgl.glTexCoord2f(0.5, 0.5)
pgl.glVertex3f(b1, b2, b3)
angle = angle + i
pgl.glEnd()
pgl.glEnableClientState(pgl.GL_VERTEX_ARRAY)
data = (pgl.GLfloat * len(array))(*array)
pgl.glVertexPointer(3, pgl.GL_FLOAT, 0, data)
pgl.glDrawArrays(pgl.GL_TRIANGLE_STRIP, 0, array_size)
pgl.glDisableClientState(pgl.GL_VERTEX_ARRAY)
@win.event
def on_draw():
global x, y, z, start_loop, run_l, param, t_prev, zRotation,frame_counter
start_time = time.time()
pgl.glClearColor(0.0, 0.0, 0.0, 0.0)
pgl.glEnable(pgl.GL_DEPTH_TEST)
if light:
pgl.glEnable(pgl.GL_LIGHTING)
pgl.glLightModelf(pgl.GL_LIGHT_MODEL_TWO_SIDE, pgl.GL_FALSE)
pgl.glEnable(pgl.GL_NORMALIZE)
else:
pgl.glDisable(pgl.GL_LIGHTING)
pgl.glDisable(pgl.GL_NORMALIZE)
pgl.glClear(pgl.GL_COLOR_BUFFER_BIT | pgl.GL_DEPTH_BUFFER_BIT)
pgl.glLoadIdentity()
pgl.glViewport(0, 0, 1300, 1000)
pgl.glMatrixMode(pgl.GL_PROJECTION)
pgl.glLoadIdentity()
pgl.glOrtho(-1300 / 4, 1300 / 4, -1000 / 4, 1000 / 4, -400, 600)
pgl.glMatrixMode(pgl.GL_MODELVIEW)
pgl.glLoadIdentity()
if light:
material_diffuse = [1.0, 1.0, 1.0, 1.0]
pgl.glMaterialfv(pgl.GL_FRONT_AND_BACK, pgl.GL_DIFFUSE,
(pgl.GLfloat * len(material_diffuse))(*material_diffuse))
if lamp1:
light5_diffuse = [1.0, 0.0, 0.0];
light5_position = [0, 0, -1.0, 0];
pgl.glEnable(pgl.GL_LIGHT5);
pgl.glLightfv(pgl.GL_LIGHT5, pgl.GL_DIFFUSE, (pgl.GLfloat * len(light5_diffuse))(*light5_diffuse));
pgl.glLightfv(pgl.GL_LIGHT5, pgl.GL_POSITION, (pgl.GLfloat * len(light5_position))(*light5_position));
pgl.glLightf(pgl.GL_LIGHT5, pgl.GL_CONSTANT_ATTENUATION, 0.0);
pgl.glLightf(pgl.GL_LIGHT5, pgl.GL_LINEAR_ATTENUATION, 0.4);
pgl.glLightf(pgl.GL_LIGHT5, pgl.GL_QUADRATIC_ATTENUATION, 0.8);
else:
pgl.glDisable(pgl.GL_LIGHT5);
if lamp2:
light6_diffuse = [0.0, 1.0, 0.0];
light6_position = [1, 0.5, -1.0, 0];
pgl.glEnable(pgl.GL_LIGHT6);
pgl.glLightfv(pgl.GL_LIGHT6, pgl.GL_DIFFUSE, (pgl.GLfloat * len(light6_diffuse))(*light6_diffuse));
pgl.glLightfv(pgl.GL_LIGHT6, pgl.GL_POSITION, (pgl.GLfloat * len(light6_position))(*light6_position));
pgl.glLightf(pgl.GL_LIGHT6, pgl.GL_CONSTANT_ATTENUATION, 0.0);
pgl.glLightf(pgl.GL_LIGHT6, pgl.GL_LINEAR_ATTENUATION, 0.4);
pgl.glLightf(pgl.GL_LIGHT6, pgl.GL_QUADRATIC_ATTENUATION, 0.8);
else:
pgl.glDisable(pgl.GL_LIGHT6);
if lamp3:
light7_diffuse = [0.0, 0.0, 1.0];
light7_position = [0.5 * math.cos(4 * math.pi / 3), 0.5 * math.sin(4 * math.pi / 3), 1.0, 0];
pgl.glEnable(pgl.GL_LIGHT7);
pgl.glLightfv(pgl.GL_LIGHT7, pgl.GL_DIFFUSE, (pgl.GLfloat * len(light7_diffuse))(*light7_diffuse));
pgl.glLightfv(pgl.GL_LIGHT7, pgl.GL_POSITION, (pgl.GLfloat * len(light7_position))(*light7_position));
pgl.glLightf(pgl.GL_LIGHT7, pgl.GL_CONSTANT_ATTENUATION, 0.0);
pgl.glLightf(pgl.GL_LIGHT7, pgl.GL_LINEAR_ATTENUATION, 0.4);
pgl.glLightf(pgl.GL_LIGHT7, pgl.GL_QUADRATIC_ATTENUATION, 0.8);
else:
pgl.glDisable(pgl.GL_LIGHT7);
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
pgl.glPushMatrix()
pgl.glTranslatef(x, y, z)
pgl.glRotatef(xRotation, 1, 0, 0)
pgl.glRotatef(yRotation, 0, 1, 0)
pgl.glRotatef(zRotation, 0, 0, 1)
pgl.glScalef(zoom, zoom, zoom)
draw_figure()
if start_loop:
start_loop = False
run_l = True
x = ((1 - (param / 100)) ** 3) * (-180) + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (100) + 3 * (
(param / 100) ** 2) * (
1 - (param / 100)) * (0) + ((param / 100) ** 3) * (200)
y = ((1 - (param / 100)) ** 3) * 70 + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (140) + 3 * (
(param / 100) ** 2) * (
1 - (param / 100)) * (140) + ((param / 100) ** 3) * (
70)
z = ((1 - (param / 100)) ** 3) * 0 + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (100) + 3 * (
(param / 100) ** 2) * (
1 - (param / 100)) * (100) + ((param / 100) ** 3) * (
0)
elif run_l:
if param < 100 and param > t_prev:
zRotation += INCREMENT
param = param + 1
t_prev = t_prev + 1
if (param == 100):
t_prev = 105
x = ((1 - (param / 100)) ** 3) * (-180) + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (100) + 3 * (
(param / 100) ** 2) * (1 - (param / 100)) * (0) + ((param / 100) ** 3) * (200)
y = ((1 - (param / 100)) ** 3) * 70 + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (140) + 3 * (
(param / 100) ** 2) * (1 - (param / 100)) * (140) + ((param / 100) ** 3) * (
70)
z = ((1 - (param / 100)) ** 3) * 0 + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (100) + 3 * (
(param / 100) ** 2) * (1 - (param / 100)) * (100) + ((param / 100) ** 3) * (
0)
if param > 0 and param < t_prev:
zRotation -= INCREMENT
param = param - 1
t_prev = t_prev - 1
if (param == 0):
t_prev = -5
x = ((1 - (param / 100)) ** 3) * (-180) + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (100) + 3 * (
(param / 100) ** 2) * (1 - (param / 100)) * (0) + ((param / 100) ** 3) * (200)
y = ((1 - (param / 100)) ** 3) * 70 + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (140) + 3 * (
(param / 100) ** 2) * (1 - (param / 100)) * (140) + ((param / 100) ** 3) * (
70)
z = ((1 - (param / 100)) ** 3) * 0 + 3 * (param / 100) * ((1 - (param / 100)) ** 2) * (100) + 3 * (
(param / 100) ** 2) * (1 - (param / 100)) * (100) + ((param / 100) ** 3) * (
0)
frame_counter +=1
# print("FPS: ", 1.0 / (time.time() - start_time))
pgl.glPopMatrix()
@win.event
def on_text_motion(motion):
global xRotation, yRotation, INCREMENT
if motion == key.UP:
xRotation -= INCREMENT
elif motion == key.DOWN:
xRotation += INCREMENT
elif motion == key.LEFT:
yRotation -= INCREMENT
elif motion == key.RIGHT:
yRotation += INCREMENT
@win.event
def on_key_press(symbol, modifiers):
global transparant, data, tr, x, y, z, INCREMENT, zRotation, light, t, start_loop, run_l, Texture, tr_temp
global xRotation, yRotation, zRotation,zoom, t_prev, texture_obj, lamp1, lamp2, lamp3, global_time, frame_counter
if symbol == key.T and not transparant:
transparant = True
elif symbol == key.T and transparant:
transparant = False
elif symbol == key.W:
x += 2.5
elif symbol == key.S:
x -= 2.5
elif symbol == key.A:
y -= 2.5
elif symbol == key.D:
y += 2.5
elif symbol == key.Q:
z -= 2.5
elif symbol == key.E:
z += 2.5
elif symbol == key.L:
light = not light
lamp1 = True
lamp2 = True
lamp3 = True
elif symbol == key.Z:
zRotation += INCREMENT
elif symbol == key.X:
zRotation -= INCREMENT
elif symbol == key.ESCAPE:
path = 'PycharmProjects/untitled/data'
fileName = 'data'
data['transparant'] = transparant
data['xRotation'] = xRotation
data['yRotation'] = yRotation
data['zRotation'] = zRotation
data['zoom'] = zoom
data['x'] = x
data['y'] = y
data['z'] = z
data['light'] = light
data['param'] = param
data['t_prev'] = t_prev
data['start_loop'] = start_loop
data['run_l'] = run_l
data['Texture'] = Texture
data['lamp1'] = lamp1
data['lamp2'] = lamp2
data['lamp3'] = lamp3
data['tr'] = tr
data['tr_temp'] = tr_temp
writeToJSONFile(path, fileName, data)
pyglet.app.exit()
elif symbol == key.P:
tr += 5
elif symbol == key.O:
if tr > 6:
tr -= 5
elif symbol == key.SPACE:
if not run_l:
tr_temp = tr
tr = 6
start_loop = True
else:
run_l = False
tr = tr_temp
elif symbol == key.M:
print("pressed")
Texture = not Texture
elif symbol == key._1:
lamp1 = not lamp1
elif symbol == key._2:
lamp2 = not lamp2
elif symbol == key._3:
lamp3 = not lamp3
elif symbol == key.F:
print("FPS: ", frame_counter / (time.time() - global_time))
frame_counter = 0
global_time = time.time()
@win.event
def on_mouse_scroll(x, y, scroll_x, scroll_y):
global zoom
if scroll_y < 0:
zoom += 0.1
elif scroll_y > 0 and zoom - 0.1 > 0:
zoom -= 0.1
@win.event
def on_mouse_press(x, y, button, modifiers):
if button == pyglet.window.mouse.LEFT:
print(x, y)
pyglet.clock.schedule_interval(run_loop, 0.1)
pyglet.app.run()
(第一次启动时关闭从 json 文件读取,然后在第一次使用 esc 关闭后,程序将读取保存的参数)
draw_figure 中的问题
最佳答案
主要问题是 GL_TRIANGLE_STRIP
不能任意连接:
1 3 5
+-----+-----+
| \ | \ |
| \ | \ |
+-----+-----+
0 2 4
7 9 11
+-----+-----+
| \ | \ |
| \ | \ |
+-----+-----+
6 8 10
如果将上述 strip 直接连接,则会生成不需要的三角形 4 - 5 - 6
和 5 - 6 -7
。
但这可以通过简单的技巧来避免。您必须添加重复的顶点。请注意,如果三角形的 2 个点相等,则三角形的面积为零。
如果将顶点 5
和 6
添加两次,则 strip 将由三角形 4 - 5 - 5
、5 连接起来- 5 - 6
、5 - 6 - 6
和 6 - 6 - 7
。每个三角形都没有大小。
我建议将顶点坐标和属性存储到列表中:
vertex = []
color = []
normal = []
textcoord = []
定义一个函数,通过坐标和属性扩展
列表:
def add_vertex(v, c, t, n):
global vertex, color, normal, textcoord
vertex.extend(v)
color.extend(c)
textcoord.extend(t)
normal.extend(n)
定义一个函数,复制列表中的最后一个坐标和属性,可用于三角形条的串联:
def repeat_vertex():
add_vertex(vertex[-3:], color[-3:], textcoord[-2:], normal[-3:])
定义另一个函数,用于构造形状(图形)。该函数必须定义所有属性(颜色、纹理坐标和法线向量),无论稍后是否使用它们:
def construct_figure():
angle = 0
t = 0
x = y = z = 0
a = 50
b = 100
for i in range(0, tr + 1):
if i >= 1:
t1, t2, t3 = a1, a2, a3
u, v = math.cos(i * 2 * math.pi / tr), math.sin(i * 2 * math.pi / tr)
a1, a2, a3 = x + a * u, y + b * v, z + 8
add_vertex([a1, a2, a3],
[u * 0.5 + 0.5, 0, v * 0.5 + 0.5],
[u * 0.5 + 0.5, v * 0.5 + 0.5],
[0, 0, -1])
b1, b2, b3 = x, y, z + 8
add_vertex([b1, b2, b3], [0.5, 0, 0.5], [0.5, 0.5], normal[-3:])
repeat_vertex()
for j in range(1, 27):
x1, y1 = a * math.cos(0), b * math.sin(0)
a1 = x1 * math.cos(t * math.pi / 360) + y1 * math.sin(t * math.pi / 360)
a2 = - x1 * math.sin(t * math.pi / 360) + y1 * math.cos(t * math.pi / 360)
a3 = z + j * 8
a01, a02, a03 = a1, a2, a3
add_vertex([a1, a2, a3], [0, 0, 0], [0, 0], normal[-3:])
repeat_vertex()
b1 = x1 * math.cos((t + 16) * math.pi / 360) + y1 * math.sin((t + 16) * math.pi / 360)
b2 = - x1 * math.sin((t + 16) * math.pi / 360) + y1 * math.cos((t + 16) * math.pi / 360)
b3 = z + j * 8 + 8
u = math.cos((t + 16) * math.pi / 360) + math.sin((t + 16) * math.pi / 360)
v = (j - 1) / 26
add_vertex([b1, b2, b3], color[-3:], [0, 0], normal[-3:])
b01, b02, b03 = b1, b2, b3
for i in range(1, tr):
x1 = a * math.cos(i * 2 * math.pi / tr)
y1 = b * math.sin(i * 2 * math.pi / tr)
t1, t2, t3 = a1, a2, a3
a1 = x1 * math.cos(t * math.pi / 360) + y1 * math.sin(t * math.pi / 360)
a2 = - x1 * math.sin(t * math.pi / 360) + y1 * math.cos(t * math.pi / 360)
a3 = z + j * 8
v = math.cos(t * math.pi / 360) + math.sin(t * math.pi / 360)
add_vertex([a1, a2, a3],
[math.cos(i * 2 * math.pi / tr)*0.5 + 0.5, j/27, math.sin(i * 2 * math.pi / tr)*0.5 + 0.5],
[(i - 1) / tr, (26 - j) / 26],
[(b2 - t2) * (a3 - b3) - (b3 - t3) * (a2 - b2), (b3 - t3) * (a1 - b1) - (b1 - t1) * (a3 - b3),
(b1 - t1) * (a2 - b2) - (b2 - t2) * (a1 - b1)])
x1 = a * math.cos(i * 2 * math.pi / tr)
y1 = b * math.sin(i * 2 * math.pi / tr)
b1 = x1 * math.cos((t + 16) * math.pi / 360) + y1 * math.sin((t + 16) * math.pi / 360)
b2 = - x1 * math.sin((t + 16) * math.pi / 360) + y1 * math.cos((t + 16) * math.pi / 360)
b3 = z + j * 8 + 8
v = math.cos((t + 16) * math.pi / 360) + math.sin((t + 16) * math.pi / 360)
add_vertex([b1, b2, b3], color[-3:], [(i - 1) / tr, (25 - j) / 26], normal[-3:])
add_vertex([a01, a02, a03], color[-3:], textcoord[-2:], normal[-3:])
add_vertex([b01, b02, b03], color[-3:], textcoord[-2:], normal[-3:])
t = t + 16
repeat_vertex()
t = 416
z = z + 144
angle = angle + t
for i in range(0, tr + 1):
u, v = math.cos(i * 2 * math.pi / tr), math.sin(i * 2 * math.pi / tr)
x1, y1 = x + a * u, y + b * v
x2 = x1 * math.cos(t * math.pi / 360) + y1 * math.sin(t * math.pi / 360)
y2 = - x1 * math.sin(t * math.pi / 360) + y1 * math.cos(t * math.pi / 360)
if i >= 1:
t1, t2, t3 = a1, a2, a3
a1, a2, a3 = x2, y2, z + 72
add_vertex([a1, a2, a3],
[u * 0.5 + 0.5, 1, v * 0.5 + 0.5],
[u * 0.5 + 0.5, v * 0.5 + 0.5],
[0, 0, 1])
if i == 0:
repeat_vertex()
b1, b2, b3 = x, y, z +72
add_vertex([b1, b2, b3], [0.5, 1, 0.5], [0.5, 0.5], normal[-3:])
angle = angle + i
repeat_vertex()
现在可以通过 glBegin
/glEnd
序列或 glDrawArrays
绘制形状:
draw_array = True # False
def draw_figure():
# [...]
if not draw_array:
pgl.glBegin(pgl.GL_TRIANGLE_STRIP)
for i in range(len(vertex)//3):
if Texture:
pgl.glTexCoord2f(textcoord[i*2], textcoord[i*2+1])
else:
pgl.glColor3f(color[i*3], color[i*3+1], color[i*3+2])
pgl.glNormal3f(normal[i*3], normal[i*3+1], normal[i*3+2])
pgl.glVertex3f(vertex[i*3], vertex[i*3+1], vertex[i*3+2])
pgl.glEnd()
else:
pgl.glEnableClientState(pgl.GL_VERTEX_ARRAY)
data = (pgl.GLfloat * len(vertex))(*vertex)
pgl.glVertexPointer(3, pgl.GL_FLOAT, 0, data)
pgl.glDrawArrays(pgl.GL_TRIANGLE_STRIP, 0, len(vertex) // 3)
pgl.glDisableClientState(pgl.GL_VERTEX_ARRAY)
可以在应用程序开始时构造形状:
construct_figure()
pyglet.clock.schedule_interval(run_loop, 0.1)
pyglet.app.run()
关于python - glDrawArrays 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56257540/
我正在处理一个个人 Java OpenGL (JOGL) 项目,我正在使用一些具有独立绘制函数和顶点的自定义对象。 public class Cube extends PhysicalObject {
我正在尝试渲染巨大的点云 (~150M),但 OpenGL 只渲染其中的一部分 (~52M)。渲染较小的数据集(glMapBufferRange,这可能会解决 4GB 的限制。 要考虑的另一件事是使用
我正在尝试渲染一个可以扩展到其他对象的四面体。 使用静态数组可以很好地绘制四面体。 但是当我将 OFF 文件读入动态数组时,什么也没有出现。编译时没有出现错误。 GLfloat *tetra_vert
我尝试使用 glDrawArray 和 GL_TRIANGLE_STRIP 渲染纹理网格,但绘制时存在伪影,但在屏幕上分布不均匀。 Screenshot of the problem. 这是我使用的代
伪代码: void draw() { Vertex* vertices = scene.GetVertexArray(); glEnableClientState(...);
我有一个未声明顶点属性的顶点着色器。它根据 UBO、gl_VertexId 和 gl_InstanceID 计算所有需要的值。 我know必须绑定(bind)非零 VAO 才能渲染。 那么,在当前 V
我正在关注一些初学者 OpenGL 教程,并且对这段代码有点困惑: glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject); //Bind GL_ARRAY
我正在尝试在 glDrawArray 上修改程序。如果我只使用glVertex3f一切都很好,如果我使用glDrawArrays`作为相同的顶点值,除了图形之外,我还会得到一些随机线。 与glDraw
我在 python3 中有这段代码,它不能在 Windows 机器上运行,但可以在 Linux 机器上运行。我绘制了一个绿色屏幕和一个红色三角形,但红色三角形仅在我退出时出现。 import pyga
我正在尝试遵循 [this][1] 简单教程,但在到达“glDrawArrays”时出现以下错误: openGLTest.exe 中 0x03D7598E (nvoglv32.dll) 处的未处理异常
我正在使用以下代码在某些指定坐标处绘制一条绿线 GLfloat colors[] = {0,1,0,1, 0,1,0,0.5}; CGPoint v[] = {{p1.x, p1.y},
我使用 vector 来存储顶点和法线数据 vector vertex; vector normal; 例如: normal.push_back(-1); normal.push_back(0); n
我正在尝试做一个简单的 Pong 游戏,但我遇到了一些问题。本质上,我有一个由四个点组成的数组,x 和 y 值表示一个硬编码的球,我需要让那个球正确显示。当我尝试使用 glDrawArray 时,我一
我最近发现 glDrawArrays 在每一帧上分配和释放大量内存。我怀疑它与 openGL 探查器报告的“Shaders compiled outside initialization”问题有关。这
当我尝试使用 glDrawArrays 绘制圆时,它显示四分之一 circle 由代码生成的 VBO 是正确的。顺便说一句,没有 0,0,0 这样的坐标。它似乎只绘制正顶点,但如果我将顶点乘以 -1
我在 openGL 的固定流水线上花了很多时间,最近开始学习可编程流水线。我认识我的画家,着色器类不是问题,因为它们使用固定功能管道的东西。我似乎无法让 glDrawArrays 为我的生活工作。 我
在循环遍历我想在 3D 引擎中渲染的所有对象时,尝试调用时出现错误 glDrawArrays(mesh->primitiveType, 0, mesh->vertexCount); 因为它试图从位置
好的,所以我仍在努力让它发挥作用。我的代码的重要部分是: def __init__(self, vertices, normals, triangles): self.bufferVertic
在通过 lwjgl 学习如何使用 OpenGL 3.2 时,我遵循了 here 上的教程.我一直在方法调用 glDrawArrays 上收到无效操作错误。如果我从教程中复制源代码,甚至会发生此错误。
我有一堆要绘制的多边形数据。我提取了那个绘图代码,现在它看起来像这样 for (int Index = 0; Index < Count; Index++) { glDrawArrays(GL
我是一名优秀的程序员,十分优秀!