python - PyopenGL glReadPixels -


i tried use glreadpixels method color code simple triangle in screen, without secondary render functions, etc. didn't give result. code:

import pygame pg opengl.gl import *   pg.display.set_mode((500,500),pg.opengl) glclearcolor(0.5,0.0,0.5,0.0) done=0  def first():     glcolor3f(0.5,0.6,0.7)     glbegin(gl_triangles)     glvertex(0.0,0.0,0.0)     glvertex(1.0,0.0,0.0)     glvertex(0.0,1.0,0.0)     glend() cl=0 clock=pg.time.clock() while not done:     event in pg.event.get():         if event.type==pg.quit: done=1         elif event.type==pg.mousebuttondown:             pos=pg.mouse.get_pos()             color=glreadpixels(pos[0],pos[1],1,1,gl_rgb,gl_float)             print color, pos[0], pos[1])        glclear(gl_color_buffer_bit)     first()     pg.display.flip()     clock.tick(20) pg.quit() 

but gives same color output: [[[ 0.50196081 0. 0.50196081]]] 288 217 how can fix it?

your main problem glreadpixels accepts bottom-left origin , pygame gives top-left.

first, should save pygame surface (for reason demonstrate). so:

window = pg.display.set_mode((500,500),pg.opengl) 

now can access window.width , window.height. glreadpixels proper place:

color=glreadpixels(x,window.height-y,1,1,gl_rgb,gl_float) 

ps: if want most recent color, should put colour detection after first() before pg.display.flip() (opengl bound buffer (unless specify otherwise (but wouldn't want to)))

edit: pg, not py

edit: wrong, it's in pixels. bad.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -