Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

OpenGL GlReadPixels

$
0
0

I have been working with OpenGL recently seeing if I could rewrite the GDI graphics end of the game engine I have been working on. http://www.autoitscript.com/forum/topic/145101-game-engine-40/

It has been going well and I have been making a lot of progress so far. Most recently I changed the perspective to isometric view (see the top left image). I then decided as a test to make the entire view rotateable. (top right and bottom left images) This all worked but as you can imagine, tile picking doesn't work anymore.

 

2gv639u.png

I have been looking into the best way to do the tile picking and came to a conclusion that there are 3 methods. Ray casting, using the GL_SELECT rendering mode, or using color picking on an underlying and never visible layer when necessary. I decided on color picking by assigning each tile a color (bottom right image) and using the GlReadPixel function at the mouse coordinates. I would only need to check the colors on mouse clicks and drawing the color tiles in a display list made for little to no speed loss.

 

Unfortunately I can't seem to get the GlReadPixels function to work properly. I found two variations of the function in searches.

Func _glReadPixels($x, $y, $width, $height, $format, $type, ByRef $pixels)     DllCall( 'opengl32.dll', 'none', 'glReadPixels', _     'int', $x, _     'int', $y, _     'int', $width, _     'int', $height, _     'uint', $format, _     'uint', $type, _     'ptr', DllStructGetPtr( $pixels)) EndFunc Func glReadpixels($x, $y, $width, $height, $format, $type, $pixels)     DllCall("opengl32.dll", "none", "glReadpixels", "int", $x, "int", $y, "int", $width, "int", $height, "uint", $format, "uint", $type, "dword", $pixels) EndFunc

I have been trying all sort of guess and test calls to get the correct return values which should be floats of the red, green, and blue values or even integers between 0 and 255 representing the values but can't seem to get the function to return anything but 0. I'm not very knowlegeable about pointers and dllstructs and was wondering if anyone could help please.

 

Some things I have tried:

Opt("MouseCoordMode", 2) ;to ensure correct window based coordinates $Mouse = MouseGetPos() $tColors = DllStructCreate("BYTE[10]") ;also tested as a float Global $pColors = DllStructGetPtr($tColors) _glReadpixels($Mouse[0], $Mouse[1], 1, 1, $GL_RGBA, $GL_UNSIGNED_BYTE, $pColors) MsgBox(0, "", DllStructGetData($tColors, 1))

Msdn states that the correct function syntax would be as follows:

void WINAPI glReadPixels(
  GLint x,
  GLint y,
  GLsizei width,
  GLsizei height,
  GLenum format,
  GLenum type,
  GLvoid *pixels
);

 

I would appreciate any help with this. Thanks.


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>