pyopengl-users Mailing List for PyOpenGL (Page 4)
Brought to you by:
mcfletch
You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(81) |
Oct
(41) |
Nov
(55) |
Dec
(14) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(34) |
Feb
(3) |
Mar
(16) |
Apr
(5) |
May
(10) |
Jun
(13) |
Jul
(24) |
Aug
(14) |
Sep
(14) |
Oct
(9) |
Nov
(10) |
Dec
(16) |
2003 |
Jan
(25) |
Feb
(59) |
Mar
(9) |
Apr
(21) |
May
(54) |
Jun
(4) |
Jul
(16) |
Aug
(19) |
Sep
(19) |
Oct
(15) |
Nov
(13) |
Dec
(22) |
2004 |
Jan
(19) |
Feb
(8) |
Mar
(20) |
Apr
(16) |
May
(13) |
Jun
(18) |
Jul
(18) |
Aug
(14) |
Sep
(24) |
Oct
(47) |
Nov
(20) |
Dec
(10) |
2005 |
Jan
(23) |
Feb
(31) |
Mar
(11) |
Apr
(29) |
May
(18) |
Jun
(7) |
Jul
(11) |
Aug
(12) |
Sep
(8) |
Oct
(4) |
Nov
(11) |
Dec
(7) |
2006 |
Jan
(7) |
Feb
(8) |
Mar
(15) |
Apr
(3) |
May
(8) |
Jun
(25) |
Jul
(19) |
Aug
(3) |
Sep
(17) |
Oct
(27) |
Nov
(24) |
Dec
(9) |
2007 |
Jan
(6) |
Feb
(43) |
Mar
(33) |
Apr
(8) |
May
(20) |
Jun
(11) |
Jul
(7) |
Aug
(8) |
Sep
(11) |
Oct
(22) |
Nov
(15) |
Dec
(18) |
2008 |
Jan
(14) |
Feb
(6) |
Mar
(6) |
Apr
(37) |
May
(13) |
Jun
(17) |
Jul
(22) |
Aug
(16) |
Sep
(14) |
Oct
(16) |
Nov
(29) |
Dec
(13) |
2009 |
Jan
(7) |
Feb
(25) |
Mar
(38) |
Apr
(57) |
May
(12) |
Jun
(32) |
Jul
(32) |
Aug
(35) |
Sep
(10) |
Oct
(28) |
Nov
(16) |
Dec
(49) |
2010 |
Jan
(57) |
Feb
(37) |
Mar
(22) |
Apr
(15) |
May
(45) |
Jun
(25) |
Jul
(32) |
Aug
(7) |
Sep
(13) |
Oct
(2) |
Nov
(11) |
Dec
(28) |
2011 |
Jan
(35) |
Feb
(39) |
Mar
|
Apr
(25) |
May
(32) |
Jun
(17) |
Jul
(29) |
Aug
(10) |
Sep
(26) |
Oct
(9) |
Nov
(28) |
Dec
(4) |
2012 |
Jan
(24) |
Feb
(47) |
Mar
(4) |
Apr
(8) |
May
(9) |
Jun
(6) |
Jul
(4) |
Aug
(1) |
Sep
(4) |
Oct
(28) |
Nov
(2) |
Dec
(2) |
2013 |
Jan
(11) |
Feb
(3) |
Mar
(4) |
Apr
(38) |
May
(15) |
Jun
(11) |
Jul
(15) |
Aug
(2) |
Sep
(2) |
Oct
(4) |
Nov
(3) |
Dec
(14) |
2014 |
Jan
(24) |
Feb
(31) |
Mar
(28) |
Apr
(16) |
May
(7) |
Jun
(6) |
Jul
(1) |
Aug
(10) |
Sep
(10) |
Oct
(2) |
Nov
|
Dec
|
2015 |
Jan
(6) |
Feb
(5) |
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(2) |
Oct
(1) |
Nov
(19) |
Dec
|
2016 |
Jan
(6) |
Feb
(1) |
Mar
(7) |
Apr
|
May
(6) |
Jun
|
Jul
(3) |
Aug
(7) |
Sep
|
Oct
(2) |
Nov
(2) |
Dec
|
2017 |
Jan
|
Feb
(6) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
|
2018 |
Jan
(9) |
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(6) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: Uğur G. <ugu...@gm...> - 2016-05-28 00:36:00
|
Dear Pyopengl users, I am a beginner who studies OpenGL using PyOpenGL. I want to learn post-processing effects and as the first step I want to be able to render a scene into a FBO and then render that FBO on a quad that cover the whole screen. The python code I am running is this: https://gist.github.com/vug/2c7953d5fdf750c727af249ded3e9018 I combined parts from several tutorials I found on the internet. I suspect that nothing is written to the texture of FBO. Sometimes I have a solid black window, and sometimes there are random noise at some parts of the window (probably this happens when texture buffer is not filled with zeros). I am using Python 3.5.0 numpy==1.11.0 PyOpenGL==3.1.0 PyOpenGL-accelerate==3.1.0 I appreciate if anyone can direct me on how to render on an offscreen framebuffer via PyOpenGL. Regards, ugur |
From: Oly <ol...@gm...> - 2016-03-29 08:07:42
|
fair enough i will keep an eye out to see if any one takes up that project, On Fri, 25 Mar 2016 at 19:31 Ian Mallett <ia...@ge...> wrote: > It would probably be a separate project (OpenGL and Vulkan are > orthogonal), but I too would be interested in Python+Vulkan in the future. > Ian > > ------------------------------------------------------------------------------ > Transform Data into Opportunity. > Accelerate data analysis in your applications with > Intel Data Analytics Acceleration Library. > Click to learn more. > http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > |
From: Ian M. <ia...@ge...> - 2016-03-25 19:30:29
|
It would probably be a separate project (OpenGL and Vulkan are orthogonal), but I too would be interested in Python+Vulkan in the future. Ian |
From: Oly <ol...@gm...> - 2016-03-25 19:04:51
|
not sure quite how this works is this part of opengl or a new library, but will we see support for vulkan or would this be a completely separate project ? Just curious if there is anything in place that will allow us to use python with vulkan in the near future. |
From: Ian M. <ia...@ge...> - 2016-03-20 22:48:00
|
Not sure, but doesn't wglGetCurrentDC require a context to be current? |
From: Prashant S. <ani...@ya...> - 2016-03-20 14:37:04
|
Hi, Windows 7 x64Python 2.7.11 x64PyOpenGL 3.1.1b1 In a simple program attached here, I am getting crash while getting wglGetCurrentDC(). How ever it's working fine in an another simple program whereI'm drawing a simple glutSphere. It's printing a long but then program is getting crashed. #!/usr/bin/env python # -*- coding: utf-8 -*- from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from OpenGL.arrays import vbo from OpenGL import platform as gl_platform import numpy import sys width = 800 height = 600 num_particles = 10000 time_step = .005 mouse_down = False mouse_old = {'x': 0., 'y': 0.} rotate = {'x': 0., 'y': 0., 'z': 0.} translate = {'x': 0., 'y': 0., 'z': 0.} initial_translate = {'x': 0., 'y': 0., 'z': -2.5} def glut_window(): glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(width, height) glutInitWindowPosition(0, 0) window = glutCreateWindow("Particle Simulation") glutDisplayFunc(on_display) # Called by GLUT every frame glutKeyboardFunc(on_key) glutMouseFunc(on_click) glutMotionFunc(on_mouse_move) glutTimerFunc(10, on_timer, 10) # Call draw every 30 ms glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60., width / float(height), .1, 1000.) return(window) def initial_buffers(num_particles): np_position = numpy.ndarray((num_particles, 4), dtype=numpy.float32) np_color = numpy.ndarray((num_particles, 4), dtype=numpy.float32) np_velocity = numpy.ndarray((num_particles, 4), dtype=numpy.float32) np_position[:,0] = numpy.sin(numpy.arange(0., num_particles) * 2.001 * numpy.pi / num_particles) np_position[:,0] *= numpy.random.random_sample((num_particles,)) / 3. + .2 np_position[:,1] = numpy.cos(numpy.arange(0., num_particles) * 2.001 * numpy.pi / num_particles) np_position[:,1] *= numpy.random.random_sample((num_particles,)) / 3. + .2 np_position[:,2] = 0. np_position[:,3] = 1. np_color[:,:] = [1.,1.,1.,1.] # White particles np_velocity[:,0] = np_position[:,0] * 2. np_velocity[:,1] = np_position[:,1] * 2. np_velocity[:,2] = 3. np_velocity[:,3] = numpy.random.random_sample((num_particles, )) gl_position = vbo.VBO(data=np_position, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) gl_position.bind() gl_color = vbo.VBO(data=np_color, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) gl_color.bind() return (np_position, np_velocity, gl_position, gl_color) def on_timer(t): glutTimerFunc(t, on_timer, t) glutPostRedisplay() def on_key(*args): if args[0] == '\033' or args[0] == 'q': sys.exit() def on_click(button, state, x, y): mouse_old['x'] = x mouse_old['y'] = y def on_mouse_move(x, y): rotate['x'] += (y - mouse_old['y']) * .2 rotate['y'] += (x - mouse_old['x']) * .2 mouse_old['x'] = x mouse_old['y'] = y def on_display(): """Render the particles""" glFlush() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # Handle mouse transformations glTranslatef(initial_translate['x'], initial_translate['y'], initial_translate['z']) glRotatef(rotate['x'], 1, 0, 0) glRotatef(rotate['y'], 0, 1, 0) #we switched around the axis so make this rotate_z glTranslatef(translate['x'], translate['y'], translate['z']) # Render the particles glEnable(GL_POINT_SMOOTH) glPointSize(1) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # Set up the VBOs gl_color.bind() glColorPointer(4, GL_FLOAT, 0, gl_color) gl_position.bind() glVertexPointer(4, GL_FLOAT, 0, gl_position) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) # Draw the VBOs glDrawArrays(GL_POINTS, 0, num_particles) glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_VERTEX_ARRAY) glDisable(GL_BLEND) glutSwapBuffers() window = glut_window() (np_position, np_velocity, gl_position, gl_color) = initial_buffers(num_particles) print gl_platform.GetCurrentContext() from OpenGL import WGL print WGL.wglGetCurrentDC() glutMainLoop() CheersPrashant |
From: Ian M. <ia...@ge...> - 2016-03-10 20:44:00
|
On Thu, Mar 10, 2016 at 4:46 AM, Jorge <gus...@gm...> wrote: > However I have been looking for a way to pick 3d objects. I have seen that > the way is creating an additional buffer that is not showed and select from > this buffer based on a color assigned to each object. This is the theory > however I can't manage to create or find a basic example. > There are several ways. Modern game engines just raytrace that one pixel on the CPU to find out what you're over. This is the "right" solution. For a GPU solution, the basic idea is to render everything a different color, and then read the color under your pixel. The basic idea here is to use a separate pass. There are fancy names for this--"picking buffer", and so on--but fundamentally they don't do anything more complex than this. But since you are really new to OpenGL, there's an even simpler way. When you begin the frame, your depth value has been cleared to 1.0. Now render an object and check the depth again. If the depth value is less than the previous value, then you hit the object you just rendered. Repeat until you've drawn your whole frame. This will be pretty slow, but it has the advantage that you don't need to try to find non-overlapping colors or worry about color precision issues or passing the right thing to your shaders. glReadPixels is the command you want for looking up the depth. Ian |
From: Jorge <gus...@gm...> - 2016-03-10 11:46:54
|
Hi. I am really new to opengl. I am using pyqt tutorials and pyopengl to show objects like they say here: https://github.com/Werkov/PyQt4/blob/master/examples/opengl/hellogl.py However I have been looking for a way to pick 3d objects. I have seen that the way is creating an additional buffer that is not showed and select from this buffer based on a color assigned to each object. This is the theory however I can't manage to create or find a basic example. In the example I am using it is using GL.glCallList(self.object) to represent the object based on the list of instrucction programmed before. I now that in the def paintGL(self): I must repaint the buffer and the color pick selection buffer. My question is: Could you give me a clue how to create the secondary buffer? Kind regards and sorry for this basic question. Jorge |
From: Matthew E. <mat...@gm...> - 2016-02-09 04:43:56
|
The pyopengl-based python script at... https://github.com/glumpy/glumpy/blob/master/examples/tutorial/quad-glut.py ...works perfectly on my desktop computer, producing a colourful window. Unfortunately, when run on my laptop, it only produces a black window, with no error or warning messages. I am running Ubuntu 15.10, but I had this same problem on 14.04 (in fact I upgraded to 15.10 to see if that might help solve this problem). Other opengl applications run well. For instance glxgears works, and I have a python script that uses FTGL to display some text, and this works correctly. Below are the output of some command-line queries to show details of my hardware and drivers. Please let me know if any other information could help resolve this strange bug. Any suggestions for things to try would be much appreciated! Thanks in advance *glxinfo | grep -i version*server glx version string: 1.4 client glx version string: 1.4 GLX version: 1.4 OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.0-devel (git-3fba517 2016-01-28 trusty-oibaf-ppa) OpenGL core profile shading language version string: 3.30 OpenGL version string: 3.0 Mesa 11.2.0-devel (git-3fba517 2016-01-28 trusty-oibaf-ppa) OpenGL shading language version string: 1.30 OpenGL ES profile version string: OpenGL ES 3.0 Mesa 11.2.0-devel (git-3fba517 2016-01-28 trusty-oibaf-ppa) OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00 *sudo lshw -c video* *-display description: VGA compatible controller product: 3rd Gen Core processor Graphics Controller vendor: Intel Corporation physical id: 2 bus info: pci@0000:00:02.0 version: 09 width: 64 bits clock: 33MHz capabilities: msi pm vga_controller bus_master cap_list rom configuration: driver=i915 latency=0 resources: irq:28 memory:f7800000-f7bfffff memory:e0000000-efffffff ioport:f000(size=64) |
From: Ian M. <ia...@ge...> - 2016-01-20 19:31:03
|
On Wed, Jan 20, 2016 at 12:02 PM, Nicolas P. Rougier < Nic...@in...> wrote: > Thanks for your question Ian ! While trying to make a screenshot I found > the answer. > > The rotating cube is displayed partially and it comes worse and worse, as > if the depth buffer was not cleared. > > And it is actually the case. I was not aware that the glClear takes the > depth mask into account > I see the problem now. Yeah, glClear counts as a change to the depth buffer, so it should be affected by the depth mask. Ian |
From: Nicolas P. R. <Nic...@in...> - 2016-01-20 19:02:21
|
Thanks for your question Ian ! While trying to make a screenshot I found the answer. The rotating cube is displayed partially and it comes worse and worse, as if the depth buffer was not cleared. And it is actually the case. I was not aware that the glClear takes the depth mask into account, meaning that: gl.glDepthMask(gl.GL_FALSE) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) does not clear the depth buffer at all, while: gl.glDepthMask(gl.GL_TRUE) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) works. Nicolas > On 20 Jan 2016, at 18:50, Ian Mallett <ia...@ge...> wrote: > > On Wed, Jan 20, 2016 at 12:13 AM, Nicolas P. Rougier <Nic...@in...> wrote: > I'm having a problem using the glDepthMask() function. I've made a simple example to show the problem: > > https://gist.github.com/rougier/188c4771dab1694a074e > This is a nice example. > > With the glDepthMask(True) / glDepthMask(False) commented out, the display is fine. But with them, the display is totally screwed. I would like to know if you get the same output or if this is only on my machine ? > I'm having trouble running the sample, since "glut.glutInit()" fails: > Traceback (most recent call last): > File "C:\Users\Ian Mallett\Desktop\glut-cube.py", line 127, in <module> > glut.glutInit() > File "C:\dev\Python33\lib\site-packages\OpenGL\GLUT\special.py", line 326, in glutInit > _base_glutInit( ctypes.byref(count), holder ) > TypeError: 'NoneType' object is not callable > Mike, it was Python 3.3.0, PyOpenGL 3.1.0b2. > > However, the code looks fine otherwise to me. Perhaps, can you clarify what "the display is totally screwed" means? > > Ian > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140_______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: Nicolas P. R. <Nic...@in...> - 2016-01-20 18:01:18
|
glDepthMask(0) is supposed to prevent writing to the depth buffer (but reading is ok) Usually it is 1 by default (writing enabled) but what I don't get is that simply setting it off then on leads to weird results (while it should be no different than default). I'm probably missing something obvious. Thanks for testing. Nicolas > On 20 Jan 2016, at 18:57, Chris Barker <chr...@no...> wrote: > > I can't offer any suggestions, but the display goes to heck for me, too. > > python 2.7.11 > OpenGL.__version__: '3.1.1a1' > > OS-X 10.10 > > MacBook Pro 2015 > > What is glDepthMask supposed to do? > > -Chris > > > > On Tue, Jan 19, 2016 at 11:13 PM, Nicolas P. Rougier <Nic...@in...> wrote: > > Hi all, > > > I'm having a problem using the glDepthMask() function. I've made a simple example to show the problem: > > https://gist.github.com/rougier/188c4771dab1694a074e > > > With the glDepthMask(True) / glDepthMask(False) commented out, the display is fine. But with them, the display is totally screwed. I would like to know if you get the same output or if this is only on my machine ? > > I'm using python 3.5.1 and PyOpenGL 3.1.0. If anybody has an explanation... > > > > Nicolas > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > -- > > Christopher Barker, Ph.D. > Oceanographer > > Emergency Response Division > NOAA/NOS/OR&R (206) 526-6959 voice > 7600 Sand Point Way NE (206) 526-6329 fax > Seattle, WA 98115 (206) 526-6317 main reception > > Chr...@no... |
From: Chris B. <chr...@no...> - 2016-01-20 17:58:25
|
I can't offer any suggestions, but the display goes to heck for me, too. python 2.7.11 OpenGL.__version__: '3.1.1a1' OS-X 10.10 MacBook Pro 2015 What is glDepthMask supposed to do? -Chris On Tue, Jan 19, 2016 at 11:13 PM, Nicolas P. Rougier < Nic...@in...> wrote: > > Hi all, > > > I'm having a problem using the glDepthMask() function. I've made a simple > example to show the problem: > > https://gist.github.com/rougier/188c4771dab1694a074e > > > With the glDepthMask(True) / glDepthMask(False) commented out, the display > is fine. But with them, the display is totally screwed. I would like to > know if you get the same output or if this is only on my machine ? > > I'm using python 3.5.1 and PyOpenGL 3.1.0. If anybody has an explanation... > > > > Nicolas > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
From: Ian M. <ia...@ge...> - 2016-01-20 17:50:26
|
On Wed, Jan 20, 2016 at 12:13 AM, Nicolas P. Rougier < Nic...@in...> wrote: > I'm having a problem using the glDepthMask() function. I've made a simple > example to show the problem: > > https://gist.github.com/rougier/188c4771dab1694a074e This is a nice example. > With the glDepthMask(True) / glDepthMask(False) commented out, the display > is fine. But with them, the display is totally screwed. I would like to > know if you get the same output or if this is only on my machine ? > I'm having trouble running the sample, since "glut.glutInit()" fails: Traceback (most recent call last): File "C:\Users\Ian Mallett\Desktop\glut-cube.py", line 127, in <module> glut.glutInit() File "C:\dev\Python33\lib\site-packages\OpenGL\GLUT\special.py", line 326, in glutInit _base_glutInit( ctypes.byref(count), holder ) TypeError: 'NoneType' object is not callable Mike, it was Python 3.3.0, PyOpenGL 3.1.0b2. However, the code looks fine otherwise to me. Perhaps, can you clarify what "the display is totally screwed" means? Ian |
From: Nicolas P. R. <Nic...@in...> - 2016-01-20 07:14:09
|
Hi all, I'm having a problem using the glDepthMask() function. I've made a simple example to show the problem: https://gist.github.com/rougier/188c4771dab1694a074e With the glDepthMask(True) / glDepthMask(False) commented out, the display is fine. But with them, the display is totally screwed. I would like to know if you get the same output or if this is only on my machine ? I'm using python 3.5.1 and PyOpenGL 3.1.0. If anybody has an explanation... Nicolas |
From: Florian N. <flo...@en...> - 2015-11-28 20:16:53
|
I forgot to join my lookAt function: def getLookAtMatrix(_eye, _lookat, _up): ez = _eye - _lookat ez = ez / np.linalg.norm(ez) ex = np.cross(_up, ez) ex = ex / np.linalg.norm(ex) ey = np.cross(ez, ex) ey = ey / np.linalg.norm(ey) rmat = np.eye(4) rmat[0][0] = ex[0] rmat[0][1] = ex[1] rmat[0][2] = ex[2] rmat[1][0] = ey[0] rmat[1][1] = ey[1] rmat[1][2] = ey[2] rmat[2][0] = ez[0] rmat[2][1] = ez[1] rmat[2][2] = ez[2] tmat = np.eye(4) tmat[0][3] = -_eye[0] tmat[1][3] = -_eye[1] tmat[2][3] = -_eye[2] # numpy.array * is element-wise multiplication, use dot() lookatmat = np.dot(rmat, tmat).transpose() > Le 28 nov. 2015 à 21:09, Florian NICOLAS <flo...@en...> a écrit : > > >> Le 28 nov. 2015 à 18:15, Nicolas P. Rougier <Nic...@in...> a écrit : >> >> >>> I also provide my running code (where getXRotation, getYRotation and getZRotation behave as expected) so I suppose the issue com from my perspective and lookAt matrices. >> >> >> Make sure to stick to np.float32 when you create matrices > It is done but it changes nothing apparently. Part of my problem was that I did not use numpy.dot (stupid mistake!). Could someone have a look at my lookAt function? Indeed, I do not understand why, when I set the Z component of my view vector (for example incrementing it thanks to the clock variable), the size of my cube does not decrease on screen as the distance between my camera and my cube increase. Is there any problem with my depth buffer? >> >>> >>> I have two last questions about matrices in GLSL: >>> - I have found that mat*vec4(position, 1) and vec4(position,1)*mat do not trigger any errors while the latter, in my opinion, should fail, why? >> >> See section 5.11 of GLSL spec at https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf > > Ok, I will only use mat*vect to match the mathematical theory :). I will go deeper into glsl matrix/vector operations later. > I >> >> >>> - As OpenGL and bumpy are not identically ordered (column/row major), should I always have to transpose my matrix before using OpenGL functions? >> >> You can fix the order in the shader. >> >> >> Nicolas > |
From: Florian N. <flo...@en...> - 2015-11-28 20:09:21
|
> Le 28 nov. 2015 à 18:15, Nicolas P. Rougier <Nic...@in...> a écrit : > > >> I also provide my running code (where getXRotation, getYRotation and getZRotation behave as expected) so I suppose the issue com from my perspective and lookAt matrices. > > > Make sure to stick to np.float32 when you create matrices It is done but it changes nothing apparently. Part of my problem was that I did not use numpy.dot (stupid mistake!). Could someone have a look at my lookAt function? Indeed, I do not understand why, when I set the Z component of my view vector (for example incrementing it thanks to the clock variable), the size of my cube does not decrease on screen as the distance between my camera and my cube increase. Is there any problem with my depth buffer? > >> >> I have two last questions about matrices in GLSL: >> - I have found that mat*vec4(position, 1) and vec4(position,1)*mat do not trigger any errors while the latter, in my opinion, should fail, why? > > See section 5.11 of GLSL spec at https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf Ok, I will only use mat*vect to match the mathematical theory :). I will go deeper into glsl matrix/vector operations later. I > > >> - As OpenGL and bumpy are not identically ordered (column/row major), should I always have to transpose my matrix before using OpenGL functions? > > You can fix the order in the shader. > > > Nicolas |
From: Nicolas P. R. <Nic...@in...> - 2015-11-28 17:16:01
|
> I also provide my running code (where getXRotation, getYRotation and getZRotation behave as expected) so I suppose the issue com from my perspective and lookAt matrices. Make sure to stick to np.float32 when you create matrices. > > I have two last questions about matrices in GLSL: > - I have found that mat*vec4(position, 1) and vec4(position,1)*mat do not trigger any errors while the latter, in my opinion, should fail, why? See section 5.11 of GLSL spec at https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf > - As OpenGL and bumpy are not identically ordered (column/row major), should I always have to transpose my matrix before using OpenGL functions? You can fix the order in the shader. Nicolas |
From: Florian N. <flo...@en...> - 2015-11-28 11:30:12
|
Yes it solves my problem. Thanks! > Le 27 nov. 2015 à 19:19, Nicolas P. Rougier <Nic...@in...> a écrit : > > Maybe you need to use np.uint32 for the dtype of the index array. > > Nicolas > > >> On 27 Nov 2015, at 16:20, Florian NICOLAS <flo...@en...> wrote: >> >> Yes it works (ctypes.c_void_p(0) also works). >> However, it seems that only half the cube is rendered. It is a bit strange as my vertex and associated indices come from a tutorial. >> >> >> >> ------------------------------------------------------------------------------------------------------------------------ >> NICOLAS Florian >> Ingénieur études amont - Service Etudes Générales Sonar >> THALES Underwater Systems >> ENSTA Bretagne (ex-ENSIETA) - Promotion 2014 - Spécialité SPID (Système Perception Information Décision) >> Profil PSO (Perception et Systèmes d'Observation) >> >> ________________________________________ >> De : Nicolas P. Rougier <Nic...@in...> >> Envoyé : vendredi 27 novembre 2015 16:04 >> À : Florian NICOLAS >> Cc : pyo...@li... >> Objet : Re: [PyOpenGL-Users] How to draw a cube using indices ? >> >> You've already bound your index buffer so you don't need to give it as argument. >> In your display function: >> >> gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) >> >> becomes >> >> gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, None) >> >> >> >> Nicolas >> >> >>> On 27 Nov 2015, at 14:57, Florian NICOLAS <flo...@en...> wrote: >>> >>> >>> Hi everybody! >>> >>> 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 result, I do not get any error but nothing appears on screen. >>> >>> I hope you could be of some help! >>> >>> Thanks. >>> >>> Here is my code: >>> >>> #! /usr/bin/env python >>> # -*- coding: utf-8 -*- >>> >>> import sys >>> import ctypes >>> import numpy as np >>> import OpenGL.GL as gl >>> import OpenGL.GLUT as glut >>> >>> vertex_code = """ >>> >>> uniform float scale; >>> uniform mat4 matCam; >>> attribute vec4 color; >>> attribute vec3 position; >>> varying vec4 v_color; >>> void main() >>> { >>> gl_Position = matCam*vec4(scale*position, 1.0); >>> v_color = color; >>> } """ >>> >>> fragment_code = """ >>> varying vec4 v_color; >>> void main() >>> { >>> gl_FragColor = v_color; >>> } """ >>> >>> def display(): >>> gl.glClear(gl.GL_COLOR_BUFFER_BIT) >>> #gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12) >>> gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) # render nothing (i.e. only the background color) >>> glut.glutSwapBuffers() >>> >>> def reshape(width,height): >>> gl.glViewport(0, 0, width, height) >>> >>> def keyboard( key, x, y ): >>> if key == '\033': >>> sys.exit( ) >>> >>> def timer(fps): >>> global clock >>> clock += 0.0005*1000.0/fps >>> print(clock) >>> # eye = np.array([0,0,1]) >>> # center = np.array([0,clock,0]) >>> # up = np.array([0,1,0]) >>> # mat = computeLookAtMatrix(eye, center, up) >>> theta = clock; >>> mat = np.array([[np.cos(theta), 0, np.sin(theta), 0], >>> [0, 1, 0, 0], >>> [-np.sin(theta), 0, np.cos(theta), 0], >>> [0, 0, 0, 1]]) >>> loc = gl.glGetUniformLocation(program, "matCam") >>> gl.glUniformMatrix4fv(loc, 1, False, mat) >>> >>> >>> >>> glut.glutTimerFunc(1000/fps, timer, fps) >>> glut.glutPostRedisplay() >>> >>> >>> # GLUT init >>> # -------------------------------------- >>> glut.glutInit() >>> glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) >>> glut.glutCreateWindow('Hello world!') >>> glut.glutReshapeWindow(512,512) >>> glut.glutReshapeFunc(reshape) >>> glut.glutDisplayFunc(display) >>> glut.glutKeyboardFunc(keyboard) >>> glut.glutTimerFunc(1000/60, timer, 60) >>> >>> # Build data >>> # -------------------------------------- >>> data = np.zeros(8, [("position", np.float32, 3), >>> ("color", np.float32, 4)]) >>> >>> data['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), >>> (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1) ] >>> >>> data['position'] = [ (-1,-1,1), >>> (1,-1,1), >>> (1,1,1), >>> (-1,1,1), >>> (-1,-1,-1), >>> (1,-1,-1), >>> (1,1,-1), >>> (-1,1,-1)] >>> >>> index = np.array([0,1,2, >>> 2,3,0, >>> 1,5,6, >>> 6,2,1, >>> 7,6,5, >>> 5,4,7, >>> 4,0,3, >>> 3,7,4, >>> 4,5,1, >>> 1,0,4, >>> 3,2,6, >>> 6,7,3]) >>> >>> # Build & activate program >>> # -------------------------------------- >>> >>> # Request a program and shader slots from GPU >>> program = gl.glCreateProgram() >>> vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) >>> fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) >>> >>> # Set shaders source >>> gl.glShaderSource(vertex, vertex_code) >>> gl.glShaderSource(fragment, fragment_code) >>> >>> # Compile shaders >>> gl.glCompileShader(vertex) >>> gl.glCompileShader(fragment) >>> >>> # Attach shader objects to the program >>> gl.glAttachShader(program, vertex) >>> gl.glAttachShader(program, fragment) >>> >>> # Build program >>> gl.glLinkProgram(program) >>> >>> # Get rid of shaders (no more needed) >>> gl.glDetachShader(program, vertex) >>> gl.glDetachShader(program, fragment) >>> >>> # Make program the default program >>> gl.glUseProgram(program) >>> >>> >>> # Build buffer >>> # -------------------------------------- >>> >>> # Request a buffer slot from GPU >>> buffer = gl.glGenBuffers(1) >>> >>> # Make this buffer the default one >>> gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) >>> >>> # Upload data >>> gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_DYNAMIC_DRAW) >>> >>> # same for index buffer >>> buffer_index= gl.glGenBuffers(1) >>> gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) >>> gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, index.nbytes, index, gl.GL_STATIC_DRAW) >>> >>> >>> # Bind attributes >>> # -------------------------------------- >>> stride = data.strides[0] >>> offset = ctypes.c_void_p(0) >>> loc = gl.glGetAttribLocation(program, "position") >>> gl.glEnableVertexAttribArray(loc) >>> gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) >>> gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) >>> >>> offset = ctypes.c_void_p(data.dtype["position"].itemsize) >>> loc = gl.glGetAttribLocation(program, "color") >>> gl.glEnableVertexAttribArray(loc) >>> gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) >>> gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) >>> >>> gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) >>> >>> # Bind uniforms >>> # -------------------------------------- >>> loc = gl.glGetUniformLocation(program, "scale") >>> gl.glUniform1f(loc, 0.5) >>> clock = 0 >>> >>> loc = gl.glGetUniformLocation(program, "matCam") >>> print(loc) >>> gl.glUniformMatrix4fv(loc, 1, False, np.eye(4)) >>> >>> # Enter mainloop >>> # -------------------------------------- >>> glut.glutMainLoop() >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> PyOpenGL Homepage >>> http://pyopengl.sourceforge.net >>> _______________________________________________ >>> PyOpenGL-Users mailing list >>> PyO...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > |
From: Florian N. <flo...@en...> - 2015-11-28 11:30:09
|
Hi! I am still experiencing PyOpenGL and today I implemented Perspective and LookAt matrices based on gluLookAt and gluPerspective (frustum): def perspectiveMatrix2(fovDeg, aspectRatio, near, far): ymax = near*np.tan(fovDeg*np.pi/360) xmax = ymax*aspectRatio return perspectiveMatrix(-xmax, xmax, -ymax, ymax, near, far) def perspectiveMatrix(left, right, bottom, top, near, far): mat = np.array([[2*near/(right-left), 0, (right+left)/(right-left), 0], [0, 2*near/(top-bottom), (top+bottom)/(top-bottom), 0], [0, 0, (near+far)/(near-far), 2*near*far/(near-far)], [0, 0, -1, 0]]) return mat def lookAt(eye, center, up): E = eye C = center U = up L = C-E L = L/np.linalg.norm(L) S = np.cross(L,U) S = S/np.linalg.norm(S) Uprim = np.cross(S,L) mat = np.zeros(shape=(4,4)) mat[:,0] = np.hstack([S, 0]) mat[:,1] = np.hstack([Uprim, 0]) mat[:,2] = np.hstack([-L, 0]) mat[:,3] = np.hstack([-E, 1]) return mat However it renders strange things or sometimes nothing depending on the input parameters. I also provide my running code (where getXRotation, getYRotation and getZRotation behave as expected) so I suppose the issue com from my perspective and lookAt matrices. I have two last questions about matrices in GLSL: - I have found that mat*vec4(position, 1) and vec4(position,1)*mat do not trigger any errors while the latter, in my opinion, should fail, why? - As OpenGL and bumpy are not identically ordered (column/row major), should I always have to transpose my matrix before using OpenGL functions? Thanks in advance for your help! #! /usr/bin/env python # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- # Copyright (c) 2014, Nicolas P. Rougier. All rights reserved. # Distributed under the terms of the new BSD License. # ----------------------------------------------------------------------------- import sys import ctypes import numpy as np import OpenGL.GL as gl import OpenGL.GLU as glu import OpenGL.GLUT as glut vertex_code = """ uniform float scale; uniform mat4 matCam; attribute vec4 color; attribute vec3 position; varying vec4 v_color; void main() { gl_Position = matCam*vec4(scale*position, 1.0); v_color = color; } """ fragment_code = """ varying vec4 v_color; void main() { gl_FragColor = v_color; } """ def display(): gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LESS) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) #gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 9) gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, None) glut.glutSwapBuffers() def reshape(width,height): gl.glViewport(0, 0, width, height) def keyboard( key, x, y ): if key == '\033': sys.exit( ) def perspectiveMatrix(left, right, bottom, top, near, far): mat = np.array([[2*near/(right-left), 0, (right+left)/(right-left), 0], [0, 2*near/(top-bottom), (top+bottom)/(top-bottom), 0], [0, 0, (near+far)/(near-far), 2*near*far/(near-far)], [0, 0, -1, 0]]) return mat def perspectiveMatrix2(fovDeg, aspectRatio, near, far): ymax = near*np.tan(fovDeg*np.pi/360) xmax = ymax*aspectRatio return perspectiveMatrix(-xmax, xmax, -ymax, ymax, near, far) def lookAt(eye, center, up): E = eye C = center U = up L = C-E L = L/np.linalg.norm(L) S = np.cross(L,U) S = S/np.linalg.norm(S) Uprim = np.cross(S,L) mat = np.zeros(shape=(4,4)) mat[:,0] = np.hstack([S, 0]) mat[:,1] = np.hstack([Uprim, 0]) mat[:,2] = np.hstack([-L, 0]) mat[:,3] = np.hstack([-E, 1]) return mat def getXRotation(theta): matX = np.array([[1, 0, 0, 0], [0, np.cos(theta), -np.sin(theta), 0], [0, np.sin(theta), np.cos(theta), 0], [0, 0, 0, 1], ]) return matX def getYRotation(theta): matY = np.array([[np.cos(theta), 0, np.sin(theta), 0], [0, 1, 0, 0], [-np.sin(theta), 0, np.cos(theta), 0], [0, 0, 0, 1], ]) return matY def getZRotation(theta): matZ = np.array([[np.cos(theta), -np.sin(theta), 0, 0], [np.sin(theta), np.cos(theta), 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], ]) return matZ def timer(fps): global clock clock += 0.001 * 1000.0/fps theta = clock eye = np.array([0,0,1]) center = np.array([0,0,0]) up = np.array([0,1,0]) #mat = lookAt(eye, center, up) #mat = getXRotation(clock) mat = perspectiveMatrix2(1, 4/3, 100, -5) loc = gl.glGetUniformLocation(program, "matCam") gl.glUniformMatrix4fv(loc, 1, False, mat.T) glut.glutTimerFunc(1000/fps, timer, fps) glut.glutPostRedisplay() # GLUT init # -------------------------------------- glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutCreateWindow('Hello world!') glut.glutReshapeWindow(512,512) glut.glutReshapeFunc(reshape) glut.glutDisplayFunc(display) glut.glutKeyboardFunc(keyboard) glut.glutTimerFunc(1000/60, timer, 60) # Build data # -------------------------------------- data = np.zeros(8, [("position", np.float32, 3), ("color", np.float32, 4)]) data['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1)] data['position'] = [ (1,1,1), (-1,1,1), (-1,-1,1), (+1,-1,1), (1,-1,-1), (1,1,-1), (-1,1,-1), (-1,-1,-1) ] index = np.array( [0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,6, 0,6,1, 1,6,7, 1,7,2, 7,4,3, 7,3,2, 4,7,6, 4,6,5], dtype=np.uint32) # Build & activate program # -------------------------------------- # Request a program and shader slots from GPU program = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) # Set shaders source gl.glShaderSource(vertex, vertex_code) gl.glShaderSource(fragment, fragment_code) # Compile shaders gl.glCompileShader(vertex) gl.glCompileShader(fragment) # Attach shader objects to the program gl.glAttachShader(program, vertex) gl.glAttachShader(program, fragment) # Build program gl.glLinkProgram(program) # Get rid of shaders (no more needed) gl.glDetachShader(program, vertex) gl.glDetachShader(program, fragment) # Make program the default program gl.glUseProgram(program) # Build buffer # -------------------------------------- # Request a buffer slot from GPU buffer = gl.glGenBuffers(1) # Make this buffer the default one gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) # Upload data gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_DYNAMIC_DRAW) buffer_index = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, index.nbytes, index, gl.GL_STATIC_DRAW) # Bind attributes # -------------------------------------- stride = data.strides[0] offset = ctypes.c_void_p(0) loc = gl.glGetAttribLocation(program, "position") gl.glEnableVertexAttribArray(loc) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) offset = ctypes.c_void_p(data.dtype["position"].itemsize) loc = gl.glGetAttribLocation(program, "color") gl.glEnableVertexAttribArray(loc) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LESS) # Bind uniforms # -------------------------------------- loc = gl.glGetUniformLocation(program, "scale") gl.glUniform1f(loc, 0.5) clock = 0 loc = gl.glGetUniformLocation(program, "matCam") gl.glUniformMatrix4fv(loc, 1, False, np.eye(4)) # Enter mainloop # -------------------------------------- glut.glutMainLoop() |
From: Nicolas P. R. <Nic...@in...> - 2015-11-27 18:20:02
|
Maybe you need to use np.uint32 for the dtype of the index array. Nicolas > On 27 Nov 2015, at 16:20, Florian NICOLAS <flo...@en...> wrote: > > Yes it works (ctypes.c_void_p(0) also works). > However, it seems that only half the cube is rendered. It is a bit strange as my vertex and associated indices come from a tutorial. > > > > ------------------------------------------------------------------------------------------------------------------------ > NICOLAS Florian > Ingénieur études amont - Service Etudes Générales Sonar > THALES Underwater Systems > ENSTA Bretagne (ex-ENSIETA) - Promotion 2014 - Spécialité SPID (Système Perception Information Décision) > Profil PSO (Perception et Systèmes d'Observation) > > ________________________________________ > De : Nicolas P. Rougier <Nic...@in...> > Envoyé : vendredi 27 novembre 2015 16:04 > À : Florian NICOLAS > Cc : pyo...@li... > Objet : Re: [PyOpenGL-Users] How to draw a cube using indices ? > > You've already bound your index buffer so you don't need to give it as argument. > In your display function: > > gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) > > becomes > > gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, None) > > > > Nicolas > > >> On 27 Nov 2015, at 14:57, Florian NICOLAS <flo...@en...> wrote: >> >> >> Hi everybody! >> >> 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 result, I do not get any error but nothing appears on screen. >> >> I hope you could be of some help! >> >> Thanks. >> >> Here is my code: >> >> #! /usr/bin/env python >> # -*- coding: utf-8 -*- >> >> import sys >> import ctypes >> import numpy as np >> import OpenGL.GL as gl >> import OpenGL.GLUT as glut >> >> vertex_code = """ >> >> uniform float scale; >> uniform mat4 matCam; >> attribute vec4 color; >> attribute vec3 position; >> varying vec4 v_color; >> void main() >> { >> gl_Position = matCam*vec4(scale*position, 1.0); >> v_color = color; >> } """ >> >> fragment_code = """ >> varying vec4 v_color; >> void main() >> { >> gl_FragColor = v_color; >> } """ >> >> def display(): >> gl.glClear(gl.GL_COLOR_BUFFER_BIT) >> #gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12) >> gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) # render nothing (i.e. only the background color) >> glut.glutSwapBuffers() >> >> def reshape(width,height): >> gl.glViewport(0, 0, width, height) >> >> def keyboard( key, x, y ): >> if key == '\033': >> sys.exit( ) >> >> def timer(fps): >> global clock >> clock += 0.0005*1000.0/fps >> print(clock) >> # eye = np.array([0,0,1]) >> # center = np.array([0,clock,0]) >> # up = np.array([0,1,0]) >> # mat = computeLookAtMatrix(eye, center, up) >> theta = clock; >> mat = np.array([[np.cos(theta), 0, np.sin(theta), 0], >> [0, 1, 0, 0], >> [-np.sin(theta), 0, np.cos(theta), 0], >> [0, 0, 0, 1]]) >> loc = gl.glGetUniformLocation(program, "matCam") >> gl.glUniformMatrix4fv(loc, 1, False, mat) >> >> >> >> glut.glutTimerFunc(1000/fps, timer, fps) >> glut.glutPostRedisplay() >> >> >> # GLUT init >> # -------------------------------------- >> glut.glutInit() >> glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) >> glut.glutCreateWindow('Hello world!') >> glut.glutReshapeWindow(512,512) >> glut.glutReshapeFunc(reshape) >> glut.glutDisplayFunc(display) >> glut.glutKeyboardFunc(keyboard) >> glut.glutTimerFunc(1000/60, timer, 60) >> >> # Build data >> # -------------------------------------- >> data = np.zeros(8, [("position", np.float32, 3), >> ("color", np.float32, 4)]) >> >> data['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), >> (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1) ] >> >> data['position'] = [ (-1,-1,1), >> (1,-1,1), >> (1,1,1), >> (-1,1,1), >> (-1,-1,-1), >> (1,-1,-1), >> (1,1,-1), >> (-1,1,-1)] >> >> index = np.array([0,1,2, >> 2,3,0, >> 1,5,6, >> 6,2,1, >> 7,6,5, >> 5,4,7, >> 4,0,3, >> 3,7,4, >> 4,5,1, >> 1,0,4, >> 3,2,6, >> 6,7,3]) >> >> # Build & activate program >> # -------------------------------------- >> >> # Request a program and shader slots from GPU >> program = gl.glCreateProgram() >> vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) >> fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) >> >> # Set shaders source >> gl.glShaderSource(vertex, vertex_code) >> gl.glShaderSource(fragment, fragment_code) >> >> # Compile shaders >> gl.glCompileShader(vertex) >> gl.glCompileShader(fragment) >> >> # Attach shader objects to the program >> gl.glAttachShader(program, vertex) >> gl.glAttachShader(program, fragment) >> >> # Build program >> gl.glLinkProgram(program) >> >> # Get rid of shaders (no more needed) >> gl.glDetachShader(program, vertex) >> gl.glDetachShader(program, fragment) >> >> # Make program the default program >> gl.glUseProgram(program) >> >> >> # Build buffer >> # -------------------------------------- >> >> # Request a buffer slot from GPU >> buffer = gl.glGenBuffers(1) >> >> # Make this buffer the default one >> gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) >> >> # Upload data >> gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_DYNAMIC_DRAW) >> >> # same for index buffer >> buffer_index= gl.glGenBuffers(1) >> gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) >> gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, index.nbytes, index, gl.GL_STATIC_DRAW) >> >> >> # Bind attributes >> # -------------------------------------- >> stride = data.strides[0] >> offset = ctypes.c_void_p(0) >> loc = gl.glGetAttribLocation(program, "position") >> gl.glEnableVertexAttribArray(loc) >> gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) >> gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) >> >> offset = ctypes.c_void_p(data.dtype["position"].itemsize) >> loc = gl.glGetAttribLocation(program, "color") >> gl.glEnableVertexAttribArray(loc) >> gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) >> gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) >> >> gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) >> >> # Bind uniforms >> # -------------------------------------- >> loc = gl.glGetUniformLocation(program, "scale") >> gl.glUniform1f(loc, 0.5) >> clock = 0 >> >> loc = gl.glGetUniformLocation(program, "matCam") >> print(loc) >> gl.glUniformMatrix4fv(loc, 1, False, np.eye(4)) >> >> # Enter mainloop >> # -------------------------------------- >> glut.glutMainLoop() >> ------------------------------------------------------------------------------ >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > ------------------------------------------------------------------------------ > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: Florian N. <flo...@en...> - 2015-11-27 15:20:14
|
Yes it works (ctypes.c_void_p(0) also works). However, it seems that only half the cube is rendered. It is a bit strange as my vertex and associated indices come from a tutorial. ------------------------------------------------------------------------------------------------------------------------ NICOLAS Florian Ingénieur études amont - Service Etudes Générales Sonar THALES Underwater Systems ENSTA Bretagne (ex-ENSIETA) - Promotion 2014 - Spécialité SPID (Système Perception Information Décision) Profil PSO (Perception et Systèmes d'Observation) ________________________________________ De : Nicolas P. Rougier <Nic...@in...> Envoyé : vendredi 27 novembre 2015 16:04 À : Florian NICOLAS Cc : pyo...@li... Objet : Re: [PyOpenGL-Users] How to draw a cube using indices ? You've already bound your index buffer so you don't need to give it as argument. In your display function: gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) becomes gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, None) Nicolas > On 27 Nov 2015, at 14:57, Florian NICOLAS <flo...@en...> wrote: > > > Hi everybody! > > 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 result, I do not get any error but nothing appears on screen. > > I hope you could be of some help! > > Thanks. > > Here is my code: > > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > import sys > import ctypes > import numpy as np > import OpenGL.GL as gl > import OpenGL.GLUT as glut > > vertex_code = """ > > uniform float scale; > uniform mat4 matCam; > attribute vec4 color; > attribute vec3 position; > varying vec4 v_color; > void main() > { > gl_Position = matCam*vec4(scale*position, 1.0); > v_color = color; > } """ > > fragment_code = """ > varying vec4 v_color; > void main() > { > gl_FragColor = v_color; > } """ > > def display(): > gl.glClear(gl.GL_COLOR_BUFFER_BIT) > #gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12) > gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) # render nothing (i.e. only the background color) > glut.glutSwapBuffers() > > def reshape(width,height): > gl.glViewport(0, 0, width, height) > > def keyboard( key, x, y ): > if key == '\033': > sys.exit( ) > > def timer(fps): > global clock > clock += 0.0005*1000.0/fps > print(clock) > # eye = np.array([0,0,1]) > # center = np.array([0,clock,0]) > # up = np.array([0,1,0]) > # mat = computeLookAtMatrix(eye, center, up) > theta = clock; > mat = np.array([[np.cos(theta), 0, np.sin(theta), 0], > [0, 1, 0, 0], > [-np.sin(theta), 0, np.cos(theta), 0], > [0, 0, 0, 1]]) > loc = gl.glGetUniformLocation(program, "matCam") > gl.glUniformMatrix4fv(loc, 1, False, mat) > > > > glut.glutTimerFunc(1000/fps, timer, fps) > glut.glutPostRedisplay() > > > # GLUT init > # -------------------------------------- > glut.glutInit() > glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) > glut.glutCreateWindow('Hello world!') > glut.glutReshapeWindow(512,512) > glut.glutReshapeFunc(reshape) > glut.glutDisplayFunc(display) > glut.glutKeyboardFunc(keyboard) > glut.glutTimerFunc(1000/60, timer, 60) > > # Build data > # -------------------------------------- > data = np.zeros(8, [("position", np.float32, 3), > ("color", np.float32, 4)]) > > data['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), > (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1) ] > > data['position'] = [ (-1,-1,1), > (1,-1,1), > (1,1,1), > (-1,1,1), > (-1,-1,-1), > (1,-1,-1), > (1,1,-1), > (-1,1,-1)] > > index = np.array([0,1,2, > 2,3,0, > 1,5,6, > 6,2,1, > 7,6,5, > 5,4,7, > 4,0,3, > 3,7,4, > 4,5,1, > 1,0,4, > 3,2,6, > 6,7,3]) > > # Build & activate program > # -------------------------------------- > > # Request a program and shader slots from GPU > program = gl.glCreateProgram() > vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) > fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) > > # Set shaders source > gl.glShaderSource(vertex, vertex_code) > gl.glShaderSource(fragment, fragment_code) > > # Compile shaders > gl.glCompileShader(vertex) > gl.glCompileShader(fragment) > > # Attach shader objects to the program > gl.glAttachShader(program, vertex) > gl.glAttachShader(program, fragment) > > # Build program > gl.glLinkProgram(program) > > # Get rid of shaders (no more needed) > gl.glDetachShader(program, vertex) > gl.glDetachShader(program, fragment) > > # Make program the default program > gl.glUseProgram(program) > > > # Build buffer > # -------------------------------------- > > # Request a buffer slot from GPU > buffer = gl.glGenBuffers(1) > > # Make this buffer the default one > gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) > > # Upload data > gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_DYNAMIC_DRAW) > > # same for index buffer > buffer_index= gl.glGenBuffers(1) > gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) > gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, index.nbytes, index, gl.GL_STATIC_DRAW) > > > # Bind attributes > # -------------------------------------- > stride = data.strides[0] > offset = ctypes.c_void_p(0) > loc = gl.glGetAttribLocation(program, "position") > gl.glEnableVertexAttribArray(loc) > gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) > gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) > > offset = ctypes.c_void_p(data.dtype["position"].itemsize) > loc = gl.glGetAttribLocation(program, "color") > gl.glEnableVertexAttribArray(loc) > gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) > gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) > > gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) > > # Bind uniforms > # -------------------------------------- > loc = gl.glGetUniformLocation(program, "scale") > gl.glUniform1f(loc, 0.5) > clock = 0 > > loc = gl.glGetUniformLocation(program, "matCam") > print(loc) > gl.glUniformMatrix4fv(loc, 1, False, np.eye(4)) > > # Enter mainloop > # -------------------------------------- > glut.glutMainLoop() > ------------------------------------------------------------------------------ > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: Nicolas P. R. <Nic...@in...> - 2015-11-27 15:04:33
|
You've already bound your index buffer so you don't need to give it as argument. In your display function: gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) becomes gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, None) Nicolas > On 27 Nov 2015, at 14:57, Florian NICOLAS <flo...@en...> wrote: > > > Hi everybody! > > 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 result, I do not get any error but nothing appears on screen. > > I hope you could be of some help! > > Thanks. > > Here is my code: > > #! /usr/bin/env python > # -*- coding: utf-8 -*- > > import sys > import ctypes > import numpy as np > import OpenGL.GL as gl > import OpenGL.GLUT as glut > > vertex_code = """ > > uniform float scale; > uniform mat4 matCam; > attribute vec4 color; > attribute vec3 position; > varying vec4 v_color; > void main() > { > gl_Position = matCam*vec4(scale*position, 1.0); > v_color = color; > } """ > > fragment_code = """ > varying vec4 v_color; > void main() > { > gl_FragColor = v_color; > } """ > > def display(): > gl.glClear(gl.GL_COLOR_BUFFER_BIT) > #gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12) > gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) # render nothing (i.e. only the background color) > glut.glutSwapBuffers() > > def reshape(width,height): > gl.glViewport(0, 0, width, height) > > def keyboard( key, x, y ): > if key == '\033': > sys.exit( ) > > def timer(fps): > global clock > clock += 0.0005*1000.0/fps > print(clock) > # eye = np.array([0,0,1]) > # center = np.array([0,clock,0]) > # up = np.array([0,1,0]) > # mat = computeLookAtMatrix(eye, center, up) > theta = clock; > mat = np.array([[np.cos(theta), 0, np.sin(theta), 0], > [0, 1, 0, 0], > [-np.sin(theta), 0, np.cos(theta), 0], > [0, 0, 0, 1]]) > loc = gl.glGetUniformLocation(program, "matCam") > gl.glUniformMatrix4fv(loc, 1, False, mat) > > > > glut.glutTimerFunc(1000/fps, timer, fps) > glut.glutPostRedisplay() > > > # GLUT init > # -------------------------------------- > glut.glutInit() > glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) > glut.glutCreateWindow('Hello world!') > glut.glutReshapeWindow(512,512) > glut.glutReshapeFunc(reshape) > glut.glutDisplayFunc(display) > glut.glutKeyboardFunc(keyboard) > glut.glutTimerFunc(1000/60, timer, 60) > > # Build data > # -------------------------------------- > data = np.zeros(8, [("position", np.float32, 3), > ("color", np.float32, 4)]) > > data['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), > (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1) ] > > data['position'] = [ (-1,-1,1), > (1,-1,1), > (1,1,1), > (-1,1,1), > (-1,-1,-1), > (1,-1,-1), > (1,1,-1), > (-1,1,-1)] > > index = np.array([0,1,2, > 2,3,0, > 1,5,6, > 6,2,1, > 7,6,5, > 5,4,7, > 4,0,3, > 3,7,4, > 4,5,1, > 1,0,4, > 3,2,6, > 6,7,3]) > > # Build & activate program > # -------------------------------------- > > # Request a program and shader slots from GPU > program = gl.glCreateProgram() > vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) > fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) > > # Set shaders source > gl.glShaderSource(vertex, vertex_code) > gl.glShaderSource(fragment, fragment_code) > > # Compile shaders > gl.glCompileShader(vertex) > gl.glCompileShader(fragment) > > # Attach shader objects to the program > gl.glAttachShader(program, vertex) > gl.glAttachShader(program, fragment) > > # Build program > gl.glLinkProgram(program) > > # Get rid of shaders (no more needed) > gl.glDetachShader(program, vertex) > gl.glDetachShader(program, fragment) > > # Make program the default program > gl.glUseProgram(program) > > > # Build buffer > # -------------------------------------- > > # Request a buffer slot from GPU > buffer = gl.glGenBuffers(1) > > # Make this buffer the default one > gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) > > # Upload data > gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_DYNAMIC_DRAW) > > # same for index buffer > buffer_index= gl.glGenBuffers(1) > gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) > gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, index.nbytes, index, gl.GL_STATIC_DRAW) > > > # Bind attributes > # -------------------------------------- > stride = data.strides[0] > offset = ctypes.c_void_p(0) > loc = gl.glGetAttribLocation(program, "position") > gl.glEnableVertexAttribArray(loc) > gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) > gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) > > offset = ctypes.c_void_p(data.dtype["position"].itemsize) > loc = gl.glGetAttribLocation(program, "color") > gl.glEnableVertexAttribArray(loc) > gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) > gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) > > gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) > > # Bind uniforms > # -------------------------------------- > loc = gl.glGetUniformLocation(program, "scale") > gl.glUniform1f(loc, 0.5) > clock = 0 > > loc = gl.glGetUniformLocation(program, "matCam") > print(loc) > gl.glUniformMatrix4fv(loc, 1, False, np.eye(4)) > > # Enter mainloop > # -------------------------------------- > glut.glutMainLoop() > ------------------------------------------------------------------------------ > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: Florian N. <flo...@en...> - 2015-11-27 14:29:43
|
Hi everybody! 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 result, I do not get any error but nothing appears on screen. I hope you could be of some help! Thanks. Here is my code: #! /usr/bin/env python # -*- coding: utf-8 -*- import sys import ctypes import numpy as np import OpenGL.GL as gl import OpenGL.GLUT as glut vertex_code = """ uniform float scale; uniform mat4 matCam; attribute vec4 color; attribute vec3 position; varying vec4 v_color; void main() { gl_Position = matCam*vec4(scale*position, 1.0); v_color = color; } """ fragment_code = """ varying vec4 v_color; void main() { gl_FragColor = v_color; } """ def display(): gl.glClear(gl.GL_COLOR_BUFFER_BIT) #gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12) gl.glDrawElements(gl.GL_TRIANGLES, len(index), gl.GL_UNSIGNED_INT, index) # render nothing (i.e. only the background color) glut.glutSwapBuffers() def reshape(width,height): gl.glViewport(0, 0, width, height) def keyboard( key, x, y ): if key == '\033': sys.exit( ) def timer(fps): global clock clock += 0.0005*1000.0/fps print(clock) # eye = np.array([0,0,1]) # center = np.array([0,clock,0]) # up = np.array([0,1,0]) # mat = computeLookAtMatrix(eye, center, up) theta = clock; mat = np.array([[np.cos(theta), 0, np.sin(theta), 0], [0, 1, 0, 0], [-np.sin(theta), 0, np.cos(theta), 0], [0, 0, 0, 1]]) loc = gl.glGetUniformLocation(program, "matCam") gl.glUniformMatrix4fv(loc, 1, False, mat) glut.glutTimerFunc(1000/fps, timer, fps) glut.glutPostRedisplay() # GLUT init # -------------------------------------- glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutCreateWindow('Hello world!') glut.glutReshapeWindow(512,512) glut.glutReshapeFunc(reshape) glut.glutDisplayFunc(display) glut.glutKeyboardFunc(keyboard) glut.glutTimerFunc(1000/60, timer, 60) # Build data # -------------------------------------- data = np.zeros(8, [("position", np.float32, 3), ("color", np.float32, 4)]) data['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1), (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1) ] data['position'] = [ (-1,-1,1), (1,-1,1), (1,1,1), (-1,1,1), (-1,-1,-1), (1,-1,-1), (1,1,-1), (-1,1,-1)] index = np.array([0,1,2, 2,3,0, 1,5,6, 6,2,1, 7,6,5, 5,4,7, 4,0,3, 3,7,4, 4,5,1, 1,0,4, 3,2,6, 6,7,3]) # Build & activate program # -------------------------------------- # Request a program and shader slots from GPU program = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) # Set shaders source gl.glShaderSource(vertex, vertex_code) gl.glShaderSource(fragment, fragment_code) # Compile shaders gl.glCompileShader(vertex) gl.glCompileShader(fragment) # Attach shader objects to the program gl.glAttachShader(program, vertex) gl.glAttachShader(program, fragment) # Build program gl.glLinkProgram(program) # Get rid of shaders (no more needed) gl.glDetachShader(program, vertex) gl.glDetachShader(program, fragment) # Make program the default program gl.glUseProgram(program) # Build buffer # -------------------------------------- # Request a buffer slot from GPU buffer = gl.glGenBuffers(1) # Make this buffer the default one gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) # Upload data gl.glBufferData(gl.GL_ARRAY_BUFFER, data.nbytes, data, gl.GL_DYNAMIC_DRAW) # same for index buffer buffer_index= gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, index.nbytes, index, gl.GL_STATIC_DRAW) # Bind attributes # -------------------------------------- stride = data.strides[0] offset = ctypes.c_void_p(0) loc = gl.glGetAttribLocation(program, "position") gl.glEnableVertexAttribArray(loc) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) offset = ctypes.c_void_p(data.dtype["position"].itemsize) loc = gl.glGetAttribLocation(program, "color") gl.glEnableVertexAttribArray(loc) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, buffer) gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, buffer_index) # Bind uniforms # -------------------------------------- loc = gl.glGetUniformLocation(program, "scale") gl.glUniform1f(loc, 0.5) clock = 0 loc = gl.glGetUniformLocation(program, "matCam") print(loc) gl.glUniformMatrix4fv(loc, 1, False, np.eye(4)) # Enter mainloop # -------------------------------------- glut.glutMainLoop() |
From: Stéphane A. <san...@fr...> - 2015-11-26 09:08:41
|
On 26/11/2015 09:45, Stéphane ANCELOT wrote: > On 11/11/2015 19:26, Mike C. Fletcher wrote: >> On 15/10/15 12:26, Stéphane ANCELOT wrote: >>> Hi, >>> >>> I have noticed in my recent linux systems I was no more able to use >>> GLE API with pyopengl. >>> >>> I tried reinstalling the sources, the problem is the same : >>> I can import GLE but not use any functions . >>> >>> OpenGL.error.NullFunctionError: Attempt to call an undefined >>> function gleSetJoinStyle, check for bool(gleSetJoinStyle) before calling >>> >>> I have found similar people with same problem, but no answer. >>> >>> I am a bit surprised, since setting up Release 3.0.2 from source is >>> working , but not releases 3.1.x . >>> >>> I tried using ctypes and loading libgle libs, no problem. >>> >>> So, If there is no "good" reason, to inhibit it in 3.1.x releases it >>> should work. >> >> Could you give more details as to *what* Linux systems? PyOpenGL is >> primarily written on Kubuntu machines (12.04 and 15.10) and on both >> GLE tests using PyOpenGL-Demo and OpenGLContext are all working. >> > OpenSuse 13.2 64 bits system. (you can testdrive it on susestudio.com) >> Are you sure that you've created a GL context before calling any GLE >> functions? > This is a working / running application, with context, no problem. >> I was working on getting the final 3.1.1 release out today, but it >> seems that will need to wait until we address this (afraid I haven't >> been monitoring my PyOpenGL folder as I worked on my conference >> presentation). > > It looks like you are using ctypes, so I made few investigations and > tried this : > I had the /usr/lib64/libgle.so library file in the system. > I made a symlink named "libGLE.so" in the same directory ===> now, > PyOpenGL can run gle Commands ! > > That may give you some ideas... > > without any context, the following gle command should work : > gleGetJoinStyle() > gleSetJoinStyle(...) > This more complicated than that , if I import GLU before GLE, the behaviour is not the same: linux-qhf9:~ # python Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from OpenGL.GLE import * >>> gleGetJoinStyle() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 407, in __call__ self.__name__, self.__name__, OpenGL.error.NullFunctionError: Attempt to call an undefined function gleGetJoinStyle, check for bool(gleGetJoinStyle) before calling >>> linux-qhf9:~ # python Python 2.7.8 (default, Sep 30 2014, 15:34:38) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from OpenGL.GLU import * >>> from OpenGL.GLE import * >>> gleGetJoinStyle() 274 Take care, >> Mike >> >> >> >> -- >> ________________________________________________ >> Mike C. Fletcher >> Designer, VR Plumber, Coder >> http://www.vrplumber.com >> http://blog.vrplumber.com >> >> >> ------------------------------------------------------------------------------ >> >> >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > ------------------------------------------------------------------------------ > Go from Idea to Many App Stores Faster with Intel(R) XDK > Give your users amazing mobile app experiences with Intel(R) XDK. > Use one codebase in this all-in-one HTML5 development environment. > Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs. > http://pubads.g.doubleclick.net/gampad/clk?id=254741551&iu=/4140 > > > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |