Working on an idea that uses about 99.9% 2D sprites and wanted to simply draw a line between one point and my mouse pointer, clearing and redrawing as the mouse moved around.
Can you combine these to get that effect?
I've been avoiding the GL part of B4GL, so I'm pretty raw on that aspect. I just copied and pasted from a tutorial and altered it as I thought might be necessary. All I get is a flashing screen that alternates between my 2D screen and a blank screen, no line.
So...I'm real ignorant in GL and have been trying to read up. But just wanted to find out if it's even possible. Thought it was but can't remember what makes me think that.
If you look in the Programmer's Guide you'll see there are 3 additional drawtext flags, DRAW_SPRITES_BEHIND, DRAW_SPRITES_INFRONT & DRAW_SPRITES. The guide says that they can be combined with OpenGL graphics so I don't see any reason why they can't be used to make the sprites appear behind the OpenGL objects.
I did read that but didn't know that it effected sprite/gl interaction.
Experimenting with them, DRAW_TEXT only draws text (duh) with no sprites, DRAW_SPRITES_BEHIND seems to draw only sprites with positive z order and no text, DRAW_SPRITES_INFRONT seems to only give a black screen (but nothing in GL, either), DRAW_SPRITES just shows sprites with no text.
By the way...any idea about how the combined flags work together...I mean, is there amy documentation regarding this? For example: does DrawText(DRAW_SPRITES_BEHIND or DRAW_TEXT) work differently if it's DrawText(DRAW_TEXT or DRAW_SPRITES_BEHIND)?
Also, this may be related: I've been using the X,Y coords of the sprites I want to draw the line between in the GL statement. Did I understand correctly that the coord system in GL is slightly different (Y in GL has 0 at the bottom of screen)? Would this matter? Could I be drawing the line off in LaLa Land somewhere?
The combined flags use bitmasks which are discussed here on Wikipedia. In traditional OpenGL displays the co-ordinate system would be different but in Basic4GL it isn't so that's nothing to worry about.
In the Basic4GL Programs folder there's a file called asteroiddemo.gb which uses OpenGL instead of sprites. Have you considered doing something similar?
You know, there's no reason I couldn't do this in OpenGL. It might even make a few aspects of it easier and look better and it might be a good next step in the learning process. Guess I need to do a bit of reading...
Is there any limit on the size of a texture that is applied to, say, a rectangle in GL?
Post by joeschmoe on Sept 22, 2011 18:58:06 GMT -5
Matthew or anyone,
I figured out how to do it. Now, I want to draw a line and have it run from a set point to the mouse pointer position. Heres the code I'm trying to use(just copied and pasted from a demo and tweak a bit):
Do Until pla>0
X = Mouse_X()*SpriteAreaWidth()+SprCameraX() Y = Mouse_Y()*SpriteAreaHeight()+SprCameraY()
glEnable (GL_TEXTURE_2D) glEnable (GL_CULL_FACE)
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) ' Clear screen and depth buffer glLoadIdentity() ' Reset the current modelview matrix
glTranslatef(0.0,-0.35,-4.7) ' Move into the screen 5 units
glBegin(GL_QUADS) ' Front face glTexCoord2f(0.0, 0.0): glVertex3f(-2.5, -1.2, 2.0) ' Bottom left of the texture and quad glTexCoord2f(1.0, 0.0): glVertex3f( 2.5, -1.2, 2.0) ' Bottom right of the texture and quad glTexCoord2f(1.0, 1.0): glVertex3f( 2.5, 1.2, 2.0) ' Top right of the texture and quad glTexCoord2f(0.0, 1.0): glVertex3f(-2.5, 1.2, 2.0) ' Top left of the texture and quad glend()
Works fine. Then to draw the line I used this:
If Mouse_Button(Mouse_LButton) then x1=Players(1)(1) y1=Players(1)(2) x2=X y2=Y 'glLoadIdentity() glTranslatef(0.375, 0.375, -4) glBegin(GL_LINES) glVertex2f(x1, y1): glVertex2f(x2, y2) glEnd() Else EndIf
DrawText() SwapBuffers ()
Have been fooling around with it, seeing what might work, but no line ever appears. Don't know if have I have to go through initialization again or just start the draw or what. Any ideas?
Post by joeschmoe on Sept 23, 2011 12:43:13 GMT -5
Getting very close, Matthew.
Two problems: it draws then erases the image I'm using (instead of triangle, a quad...I tinkered with the code to get that in) and then starts drawing the line. The line works fine, except that the X and Y coords seem to be about 60 pixels less for both values (again, I tinkered with code so that it would draw line from a point to the mouse).
Does this make any sense? Should I just explain what I'm trying to do more specifically?
One question: is there any free info on-line that explains what each of the commands do? I feel like the guy who gets free fish rather than learning how to fish, know what I mean?
Okay, if the image is being erased then redrawn you'll probably need to use a rubber-band line. I created some short routines back in 2007 using them but they're on another computer so I'll have to upload them tomorrow. As for an online reference, I've just uploaded a copy of the OpenGL Redbook which you can get here. (20.7 MB)