lwjgl 2d Drawing Program Approach

Started by DrAnonymous, February 20, 2007, 04:45:27

Previous topic - Next topic

DrAnonymous

I'm working on a game that allows a kid to draw on the screen.  The framework I'm using is called Slick (slick.cokeandcode.com) and uses lwjgl for its openGL access.  While I know how to program, I do not know openGL and so I don't know how to approach my problem.

In the simplest form, my problem is this:

How can I draw to the screen when the child holds the mouse down and not store the mouse coordinates for subsequent redraws of the screen?

In pseudo code I would have something like this -

draw previous image to screen
drawline from last mouse x/y position to current x/y position
store screen area to buffer

I've done this in Swing before by creating an Image, getting its graphics context and drawing to it.  I then simply draw the image to the screen.  Using lwjgl without more experience has gotten me stuck.  :(

Thanks,
Dr. A>

Kylearan

Hi,

Quote from: DrAnonymous on February 20, 2007, 04:45:27How can I draw to the screen when the child holds the mouse down and not store the mouse coordinates for subsequent redraws of the screen?

In pseudo code I would have something like this -

draw previous image to screen
drawline from last mouse x/y position to current x/y position
store screen area to buffer

I'm no OpenGL guru myself so I'm sure there are better ways to do it, but how about using glTexSubImage2D()? You could render the old screen as a texture to the screen, draw the new line, then use glTextSubImage2D() to transfer the new screen data back to the texture.

I don't know how to do it with Slick, but lwjgl should have implemented that OpenGL function. :)

-Kylearan

DrAnonymous

Someone mentioned using a pbuffer.  Would that make more sense?  Any pros or cons either way?

Thanks,
Dr.A>

Kylearan

Hi,

Quote from: DrAnonymous on February 21, 2007, 05:49:29
Someone mentioned using a pbuffer.  Would that make more sense?  Any pros or cons either way?

A pbuffer would be the better solution (faster). However, if I understand this right, pbuffers need a more advanced graphics card, and the pbuffer might get lost if a display mode change occurs - although both should not be a big problem, really.

-Kylearan