Hi folks, the following lines of code produce unexpected results. Is it just me?
draw_line(0,0, Gosu::Color::YELLOW, 0,10, Gosu::Color::YELLOW, 999)
draw_line(0,0, Gosu::Color::YELLOW, 10,0, Gosu::Color::YELLOW, 999)
This should produce two lines from the top left of my window, one vertical and one horizontal. The horizontal line is missing until I do this...
draw_line(0,1, Gosu::Color::YELLOW, 0,11, Gosu::Color::YELLOW, 999)
draw_line(0,1, Gosu::Color::YELLOW, 10,1, Gosu::Color::YELLOW, 999)
I'm using whatever comes with OSX when you do all that gem jazz.
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
Checked your code and I have the same thing, but with vertical line.
It's an unfortunate OpenGL bug, or implementation detail, or something. I think Julian has mentioned before that OpenGL doesn't really have a good, consistent way to draw a line onscreen. On some platforms, the lines will be drawn in exactly the right place; on others, they will be off by one in either direction. If you can use pre-made images of lines instead, you'll be better off. :C
What I do for this is create a 1x1 pixel white image and #draw that coloured and scaled to render orthogonal lines, rather than using #draw_line. This ensures that the lines are always pixel-perfect and will be drawn consistently in situations like this (especially true when you are trying to draw rectangular frames).
+1 This is what I was trying to suggest, but expressed more clearly. C:
Thanks for the workaround, I can live with this since I'm only using this function currently for debugging collision detection. I'd suggest noting the issue and workaround in the documentation... http://www.libgosu.org/rdoc/Gosu/Window.html#method-i-draw_line
On a related point, can anyone think of a way to get the colour value of a pixel? Perhaps then we could test for glitchy behavior on start up and use an offset based on results. Then draw_line wouldn't be so useless, and I'm guessing it's more efficient than the 1x1 image workaround. How can I find out more about the Gosu::Window.gl function?
I made a note to add it to the docs ASAP.
You can take a look at
examples/OpenGLIntegration.rb to see how
gl can be used. But I will actually replace
draw_line by a replacement that uses a 1x1px image, so that is not a good plan for the long term. And in the short term, I am not convinced that there is a speed difference at all :)
Yeah, using images is unlikely to be slower and trying to hack the current
#draw_line to work would be orders of magnitude slower (the error offset is not consistent across the screen!).
Cool, I was just guessing. I've not peered under the hood to see how Gosu works yet.
BTW Spooner, I seem to get consistent results across the screen. When I make a wrapper method that just ups the y coordinate by one it works perfectly. I assumed it was consistently off by one (platform specifically or something). But if your suggesting that's not the case, I'll forget about hacking it.
I mainly noticed this effect when drawing rectangular boxes. Some boxes would be drawn correctly, but other ones, at other positions on the screen, would have one or both the sides off by one. It seemed to be dependent on position on the screen and also seemed to be consistent across runs of the game. I'm on win7x64 using an NVidia card.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill