|
Post by joeschmoe on Sept 1, 2011 12:10:43 GMT -5
Another dumb question...
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.
|
|
|
Post by matthew on Sept 1, 2011 14:26:05 GMT -5
Hi joeschmoe there's a post here containing a program written by tom which combines Sprites & OpenGL.
|
|
|
Post by joeschmoe on Sept 2, 2011 13:25:21 GMT -5
Hi Matthew,
Will Tom's program allow the GL graphics to be drawn over some sprites and under others? Is this related to the zorder of the sprites and/or the z coordinate in the gltranslate statement?
Thanks.
|
|
|
Post by matthew on Sept 2, 2011 15:01:41 GMT -5
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 just can't seem to work out how though.
|
|
|
Post by joeschmoe on Sept 2, 2011 18:27:18 GMT -5
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. Guess you probably noticed that...
|
|
|
Post by joeschmoe on Sept 2, 2011 19:55:32 GMT -5
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?
|
|
|
Post by matthew on Sept 3, 2011 21:53:56 GMT -5
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?
|
|
|
Post by joeschmoe on Sept 4, 2011 14:51:03 GMT -5
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 5, 2011 16:09:23 GMT -5
Never mind about the last question.
|
|
|
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()
BindSprite(Mouse) SprSetPos(X,Y)
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
glBindTexture(GL_TEXTURE_2D, field) ' Select our texture
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 ()
Loop
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?
Thanks.
|
|
|
Post by Nicky Peter Hollyoake on Sept 22, 2011 19:22:48 GMT -5
Did you activate "TextMode(TEXT_OVERLAID)" if not put it at the top of your program, or anywhere that's relevent to you, just not in a loop as it only needs to be used once.
- Nicky
|
|
|
Post by joeschmoe on Sept 23, 2011 2:21:57 GMT -5
Hi Nicky,
Yes. I use the first part (Quads) to draw my background and that works fine. It's just drawing the line that doesn't seem to work.
Thanks for your help.
|
|
|
Post by matthew on Sept 23, 2011 6:51:08 GMT -5
Try the following code, it should do what you need. TextMode(TEXT_OVERLAID)
dim prevMousePosX, prevMousePosY, currMousePosX, currMousePosY
dim rtri#
prevMousePosX = ( windowwidth() / 2 ) prevMousePosY = ( windowheight() / 2 )
while (true) ' Create our 3d view glViewport (0, 0, WindowWidth(), WindowHeight()) glMatrixMode(GL_PROJECTION) glLoadIdentity () gluPerspective (60, (1.0*WindowWidth()) / WindowHeight(), 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glEnable (GL_DEPTH_TEST) glDepthFunc (GL_LEQUAL)
' Clear the screen, etc... glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) glLoadIdentity () glTranslatef(0.0,0.0,-6.0) glRotatef(rtri#,0.0,1.0,0.0) ' Draw a triangle glBegin(GL_TRIANGLES) glColor3f(1.0,0.0,0.0) glVertex3f( 0.0, 1.0, 0.0) glColor3f(0.0,1.0,0.0) glVertex3f(-1.0,-1.0, 0.0) glColor3f(0.0,0.0,1.0) glVertex3f( 1.0,-1.0, 0.0) glEnd() ' Rotate our triangle rtri# = rtri# + 0.2 ' Create our 2d screen glMatrixMode (GL_PROJECTION) glLoadIdentity () glOrtho (0, windowwidth(), windowheight(), 0, 0, 1) glDisable(GL_DEPTH_TEST) glMatrixMode (GL_MODELVIEW) glLoadIdentity() ' Get the current mouse positions currMousePosX = ( mouse_x() * windowwidth() ) currMousePosY = ( mouse_y() * windowheight() ) ' Draw in white glcolor3f(1.0, 1.0, 1.0)
' Draw our 2d line glbegin(gl_lines) glvertex2i(prevMousePosX, prevMousePosY) glvertex2i(currMousePosX, currMousePosY) glend()
' Put everything on the screen drawtext() swapbuffers()
wend
|
|
|
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?
|
|
|
Post by matthew on Sept 23, 2011 13:50:12 GMT -5
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)
|
|