pyopengl

PyOpenGL: glVertexPointer() offset problem

会有一股神秘感。 提交于 2019-12-06 04:10:39
问题 My vertices are interleaved in a numpy array (dtype = float32) like this: ... tu, tv, nx, ny, nz, vx, vy, vz, ... When rendering, I'm calling gl*Pointer() like this (I have enabled the arrays before): stride = (2 + 3 + 3) * 4 glTexCoordPointer( 2, GL_FLOAT, stride, self.vertArray ) glNormalPointer( GL_FLOAT, stride, self.vertArray + 2 ) glVertexPointer( 3, GL_FLOAT, stride, self.vertArray + 5 ) glDrawElements( GL_TRIANGLES, len( self.indices ), GL_UNSIGNED_SHORT, self.indices ) The result is

How create a camera on PyOpenGL that can do “perspective rotations” on mouse movements?

橙三吉。 提交于 2019-12-06 03:55:30
I am creating a first-person view RPG and I want to rotate the camera in PyOpenGL when I move the mouse (just like some other games like Minecraft). What function can I use to do this and how? I tried to use gluLookAt() but I don't understand how it works although I went through different sources. I don't even know if it can help. import sys,pygame from OpenGL.GL import * from OpenGL.GLU import * cmddown = False #... keypress = pygame.key.get_pressed()#Move using WASD if keypress[pygame.K_w]: glTranslatef(0,0,0.1) if keypress[pygame.K_s]: glTranslatef(0,0,-0.1) if keypress[pygame.K_d]:

ray intersection misses the target

China☆狼群 提交于 2019-12-06 00:24:46
I'm trying to pick a 3d point. I read various sites but my code doesn't work. on right mouse click: glGetFloatv(GL_MODELVIEW_MATRIX,mv_mat) glGetFloatv(GL_PROJECTION_MATRIX,p_mat) ip_mat = np.linalg.inv(mat4(p_mat)) # clip = array[ # (2*x)/window_width-1 # 1-(y*2)/window.height # -1 # 1 camera_coord = np.dot(ip_mat,clip) camera_coord = np.array([camera_coord[0,0],camera_coord[0,1],-1,0]) imv_mat = np.linalg.inv(mat4(mv_mat)) ray_world = np.dot(imv_mat,camera_coord) ray_world = np.array([ray_world[0],ray_world[1],ray_world[2]]) ray_world = ray_world/np.linalg.norm(ray_world) Intersect_sphere

Python PIL Image.tostring()

北战南征 提交于 2019-12-05 16:36:35
I'm new to Python and PIL. I am trying to follow code samples on how to load an image into to Python through PIL and then draw its pixels using openGL. Here are some line of the code: from Image import * im = open("gloves200.bmp") pBits = im.convert('RGBA').tostring() ..... glDrawPixels(200, 200, GL_RGBA, GL_UNSIGNED_BYTE, pBits) This will draw a 200 x 200 patch of pixels on the canvas. However, it is not the intended image-- it looks like it is drawing pixels from random memory. The random memory hypothesis is supported by the fact that I get the same pattern even when I attempt to draw

Transparent FrameBuffer background in OpenGL

房东的猫 提交于 2019-12-04 13:34:55
问题 I want to use glClear and glClearColor to fill a frame buffer with a colour including alpha transparency. However the framebuffer always renders as opaque when binded to a texture which is rendered to the screen. I want everything which is rendered to the framebuffer to kept their transparency. I just want to change the background. See the following code: def create_texture(surface): surface.texture = glGenTextures(1) glMatrixMode(GL_MODELVIEW) glLoadIdentity() #Loads model matrix

Implementing render-to-vertex-array, glReadPixels fails (invalid operation)

孤者浪人 提交于 2019-12-04 13:21:10
I'm trying to copy vertex data from a texture to a vertex buffer, and then draw the vertex buffer. As far as I know the best way to do this is to bind the texture to a fbo, and use glReadPixels to copy it to a vbo. However, I can't seem to get this working: glReadPixels fails with the error "invalid operation". Corrections, examples and alternate methods welcome. :) Here's the relevant code: glEnable(GL_TEXTURE_2D) w, h = 32, 32 vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) glBufferData(GL_ARRAY_BUFFER, sizeof(c_float)*w*h*4, None, GL_STREAM_COPY) glBindBuffer(GL_ARRAY_BUFFER, 0)

PyOpenGL: glVertexPointer() offset problem

半腔热情 提交于 2019-12-04 09:06:41
My vertices are interleaved in a numpy array (dtype = float32) like this: ... tu, tv, nx, ny, nz, vx, vy, vz, ... When rendering, I'm calling gl*Pointer() like this (I have enabled the arrays before): stride = (2 + 3 + 3) * 4 glTexCoordPointer( 2, GL_FLOAT, stride, self.vertArray ) glNormalPointer( GL_FLOAT, stride, self.vertArray + 2 ) glVertexPointer( 3, GL_FLOAT, stride, self.vertArray + 5 ) glDrawElements( GL_TRIANGLES, len( self.indices ), GL_UNSIGNED_SHORT, self.indices ) The result is that nothing renders. However, if I organize my array so that the vertex position is the first element

Where can I find a good online OpenGL 3.0 tutorial that doesn't use any deprecated functionality? [closed]

99封情书 提交于 2019-12-04 07:35:06
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I just purchased the fifth edition of the OpenGL SuperBible. I'm very pleased that they've avoided using deprecated functionality but

Using OpenGL with Python [closed]

妖精的绣舞 提交于 2019-12-02 17:37:21
So, I only know how to use Python, but I also know how to model in 3d. I've heard of OpenGL and I really want to learn how to use, because it seems very useful (I want to create simple games with it...). I found PyOpenGL, Python bindings for OpenGL, but I couldn't find any "real" documentation, so the only option is to study code examples and tutorials written in C++ or something. But, as I said, I only know how to use Python. What can I do about that? You should go on and read a OpenGL tutorial . Here's a pyopengl demo ; other samples are over here . Also, you can use pygame together with

glDrawElements to draw a cube in PyOpenGL

邮差的信 提交于 2019-12-02 08:14:46
问题 I recently started to learn OpenGL through Python thanks to several tutorial (especially the Nicolas P. Rougier one: http://www.labri.fr/perso/nrougier/teaching/opengl/). I am now switching to 3D and I am trying to draw a cube. Thus, I manage to get some triangles which do not render a cube (this seems to be normal as I do not duplicate my vertices and I use the glDrawArrays function). However, after, I build an index "vector" to further use the glDrawElements function to render my cube. As a