|
Post by DJLinux on Mar 19, 2012 6:39:45 GMT -5
A new version of the OpenGL Plugin. With some new cool features: Very fast memory functions. new: save and load memory buffers new: image buffers usable as textures / sprites ... new: draw points, lines, rectangles, circles, arcs and Text new: copy, blend images or parts of it new glFogCoordf Download: OpenGLPlugin.zipJoshy
|
|
|
Post by dw817 on Feb 24, 2013 10:33:37 GMT -5
Finally got that to appear. I had a B4GL game running in the background, "Diamond" while it's icon vanished from below, it continued to run invisibly. Removed it with Task Manager and got the right results (you posted above).
Your system does look powerful and I do want to take the time to learn it !
How do I get the pixels to appear at the top instead of the bottom ? I'm used to X=0 left and Y=0 top ?
And can you draw pixels without using the rectangle function and possibly have this run faster ?
I am definitely going to try and learn your system but I will need your help, and understand there is a good chance I won't do any 3D stuff, so hopefully that'll make my questions easier.
|
|
|
Post by DJLinux on Feb 24, 2013 10:59:28 GMT -5
How do I get the pixels to appear at the top instead of the bottom ? I'm used to X=0 left and Y=0 top ? It's quite easy change: gluOrtho2D(0, width, 0, height) to: gluOrtho2D(0, width, height, 0) And can you draw pixels without using the rectangle function You don't take a look at the OpenGLPlugin.rtf document ? DrawPoint() is the right command ... and possibly have this run faster ? Before i think about it. What is the goal of your efforts? DJ
|
|
|
Post by dw817 on Feb 24, 2013 12:17:36 GMT -5
Hi DJ: to: gluOrtho2D(0, width, height, 0)Gives me a black screen gluOrtho2D(0,ww,wh,0)* I read the .RTF file (have it up right now), but it doesn't have a working example program for every single command. GFA-Help gives you an example program for every single command possible in it, including print and input. Here is the help they give for PRINT And I always learn the most by samples and examples than explanation. drawpoint() doesn't have X & Y coordinates like drawrectangle() does so I didn't know to use it from the help .RTF and example programs you gave. Can you make a drawpointxy() which does ? Here is what I will really need. GFABasic is a Windows 3.1 programming language I've used for years, unfortunately it does not run in Windows 7 so I had to abandon it. It has a few unique abilities. One of which is to create virtual screens: NewDC(I) = MEMDC(_DC(1)),BMPDC(I) = CREATEBMP(1024,768) In this, when I use: SETDC NewDC(I) At this point, anything I draw is not drawn to the screen but to the biggo virtual screen so when I use: BITBLT NewDC(0),0,0,1024,768,_DC(1),0,0,SRCCOPY Where _DC(1) is the actual viewing screen. It transfers the virtual screen of NewDC(0) to the main screen so you can do flicker-free graphics. And you can make multiple virtual screens thissaways too. Ultimately I will need this, the ability to load/save off these images to the HD, and go from there. PNG format would be nice. In GFA I was forced to write a manual .BMP saver and it was really clumsy and slow. Now Blitz-Max DOES have the ability to plot pixels ONLY to one of these DC pages which you can make virtual but it has no ability to transfer regions from other virtual pages unless you do it a dot at a time which is super-slow. In Blitz-Max, I can't plot sprites or images and stuff to these virtual pages, only to the 'flipped' page. But with GFA you can get neat results cause you can do: BITBLT NewDc(1),H1,V1,X1,Y1,NewDc(0),H2,V2,SRCCOPY Which is absolutely perfect for transferring over stuff from page 1 which in this case has all the data images I need for the program, to page 0 which is what the player sees (when you transfer it to _dc(1) later which you remember is the actual display screen). or even: ~StretchBlt(NewDC(0),144 - H * Mag + J * Mag * 63 + A,A + 96 - V * Mag + I * Mag * 63,2016,2016,NewDC(10),0,0,2016,2016,SRCCOPY) Where ~stretchblt stretches the images you are transferring (no dither, that didn't exist for Windows 3.1 so it looks like kinna blocky if you don't do it right). The SRCCOPY means to copy pixels as is, XORCOPY does XOR, etc. GFA has no ALPHA ability so that's gonna be a real benefit here and I can do lasers and lights and stuff. If I can do this in B4GL, create these virtual screens using your library and can then plot pixels, rectangles, and transfer rectangular regions from other virtual screens with option to include the back background or to call that transparent for a sprite. That would be wonderful and put me about level with exactly what and where I need to work with to write this 3rd RPG Maker, surpassing what I'm doing in Blitz-Max currently. So I need to, from your library please: 1. Ability to create virtual pages up to and maybe even EXCEEDING 1024x768. (In GFA for Scenario 2, I opened up a 2016x2016 pixel page for the RPG map and scrolled around showing only a portion of it on the real screen triple-size so you actually viewed only 20% of the map at a time). 2. Ability to transfer rectangles from these virtual pages to either other virtual pages or the display screen itself, taking into account optionally if the background is 0 then it inserts the image as a sprite, etc, and taking into account if you are stretching the size smaller or larger across with proper dither effect. No need to use swapbuffers() or drawtext(). You draw to this hidden DC(0) and then just smack that onto the real screen when you're ready, you're all set with that. GFA did not have a page-swap method so I used that for 100% flicker-free graphics. 3. Ability to load/save these virtual pages to HD, doesn't have to be .PNG but that's a good choice I think. Speed being more important than file format. Whichever loads/saves the fastest, maybe .BMP, but can still be read by a paint program. ? When the program exits, do I have to free up these virtual pages or are they cleaned up automatically ? Blitz-Max cleans up everytime the program exits, either prematurely with an error of mine or when the code requested to end normally.
|
|
|
Post by dw817 on Feb 24, 2013 13:25:22 GMT -5
Here are some programs for you to try to see what I'm trying to accomplish in B4GL: Current Blitz-Max engine: www.mediafire.com/?wb9p0vzcd7bv69sTo see how I am modifying pixels, in the s3-config.txt file, change the defframe= to a new value (up to 39) and see that I am building the frame from a seamless internal background. (This is one reason I need pixel control). Test engine w audio and to show partial transparency and rotation: www.mediafire.com/?j43s3b9flveorhnPress [ESC] to exit. Completed Scenario 2 RPG Maker engine (runs in WinXP): www.mediafire.com/?l2o84oabsydhqf5Includes instructions and sample world file to explore.
|
|
|
Post by DJLinux on Feb 25, 2013 5:26:56 GMT -5
x,y are missed in the *.rtf but aviable Set one pixel in the image buffer: DrawPoint( pImage, x%, y%) (use current pen color) DrawPoint( pImage, x%, y%, rgb#() ) DrawPoint( pImage, x%, y%, rgba#() ) DrawPoint( pImage, x%, y%, r%, g%, b% ) DrawPoint( pImage, x%, y%, r%, g%, b%, a% )
I will try your demos next time
DJ
|
|
|
Post by dw817 on Feb 25, 2013 12:07:59 GMT -5
OK ! I appreciate your help on this, and it is indeed faster. drawpoint() works better than drawrectangle(). It's still slower than Blitz-Max, not sure why. Here is the code I wrote for Blitz-Max: Graphics 1024,768
image=CreateImage(512,368)
Repeat map=LockImage(image) For i=0 To 367 For j=0 To 511 WritePixel(map,j,i,rgb(Rand(0,255),Rand(0,255),Rand(0,255))) Next Next UnlockImage(image) DrawImage image,0,0 Flip Until KeyHit(32)
Function rgb(r,g,b) Return b Mod 256+(g Mod 256)*256+(r Mod 256)*65536+$ff000000 EndFunction
The $ff000000 is for ALPHA (need that at 100% or it doesn't show up) And the executable of this: www.mediafire.com/?r1r8f6bi2h6uv6fNow, here is my program using your DLL, slightly larger sourcecode: dim ww,wh sub InitOpenGL() ww=WindowWidth() wh=WindowHeight() glPixelStorei(GL_UNPACK_ALIGNMENT,1) glViewport(0, 0, ww,wh) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0,ww,0,wh) glMatrixMode(GL_MODELVIEW) glLoadIdentity() end sub
initopengl()
dim imge as img=allocimage(512,368),i,j
glClear(GL_COLOR_BUFFER_BIT) swapbuffers() glClear(GL_COLOR_BUFFER_BIT) do for i=0 to 367 for j=0 to 511 drawpoint(imge,j,i,rnd()%256,rnd()%256,rnd()%256) next next glRasterPos2i(0,0) glDrawPixels(imge) swapbuffers() loop until inkey$()=" "
And the source and executable and your DLL for this B4GL program: www.mediafire.com/?qs5fsf3a6a20et7It definitely runs slower. OK, also your earlier code of: to: gluOrtho2D(0, width, height, 0)converted to: gluOrtho2D(0,ww,wh,0)Just gives me a black screen for this program.
|
|
|
Post by dw817 on Feb 26, 2013 10:14:35 GMT -5
x,y are missed in the *.rtf but aviable Set one pixel in the image buffer: DrawPoint( pImage, x%, y%) (use current pen color) DrawPoint( pImage, x%, y%, rgb#() ) DrawPoint( pImage, x%, y%, rgba#() ) DrawPoint( pImage, x%, y%, r%, g%, b% ) DrawPoint( pImage, x%, y%, r%, g%, b%, a% ) I will try your demos next time DJ Also, for that current Blitz-Max engine above, I know the menus are just dummy and the vertical placement is off for the filer, I'm just working on that code, so that's not an error - it's just not finished code.
|
|
|
Post by shadow008 on Oct 18, 2013 21:02:48 GMT -5
Long time no post... So I was messing with the GlDrawElements command when I came across a bug. Code: sub InitOpenGL() dim MaxVertex,MaxIndex glGetIntegerv(GL_MAX_ELEMENTS_VERTICES,MaxVertex) glGetIntegerv(GL_MAX_ELEMENTS_INDICES ,MaxIndex) if MaxVertex<1 or MaxIndex<1 then print "sorry no support for elements" beep():end end if glLoadIdentity() gluLookAt(0,32,-1, 0,0,0, 0,1,0) end sub
data 1, 0, 0 data 0, 1, 0 data 0, 0, 1 data 1, 1, 0 data 0, 1, 1 data 1, 0, 1
InitOpenGL()
dim Col#(5,2) ' 6 colors with r,g,b dim i, j
for i=0 to 5 for j=0 to 2: read Col#(i,j):next next
dim Rot#
dim size = 16
dim vert((size + 1) * (size + 1) - 1)(2) as single dim Index((size+1) * (size+1))(3)
dim x,y for x = 0 to size' - 1 for y = 0 to size' -1
Vert((x * (size + 1)) + y)(0) = y Vert((x * (size + 1)) + y)(1) = 0 Vert((x * (size + 1)) + y)(2) = x
next next
for x = 0 to size -1 for y = 0 to size - 1 'Index( Index((x * size) + y)(0) = (x * size) + y + x Index((x * size) + y)(1) = (x * size) + y + 1 + x Index((x * size) + y)(2) = ((x+1) * size) + y + 2 + x Index((x * size) + y)(3) = ((x+1) * size) + y + 1 + x next
next
dim MEM pVer=AllocFloatPointer(Vert) dim MEM pCol=AllocFloatPointer(Col#) dim MEM pInd=AllocbytePointer(Index)
glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) glVertexPointer(3, GL_FLOAT, 0, pVer) glColorPointer(3,GL_FLOAT, 0, pCol) glClearColor(.5,.7,.1,1) while inkey$()="" glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) glPushMatrix() glScalef(.5,.5,.5) 'glRotatef(Rot#, 0.5,0.25,0.125) ' draw 6 quads with 24 coords from index array glDrawElements(GL_quads, size * size * 4, GL_UNSIGNED_SHORT, pInd) glPopMatrix()
SwapBuffers() WaitTimer(1000/50) Rot#=Rot#+1 if Mouse_Button(MOUSE_LBUTTON) then glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) endif wend glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) The error comes up at line 83 with GlDrawElements, with a generic "an exception has occured" If the third param is changed to "GL_UNSIGNED_BYTE", the error goes away, but if you run that, you'll see the indicies overflow at 256 and reset, which isn't very pretty. Also, switching: dim MEM pInd=AllocbytePointer(Index) to dim MEM pInd=AllocShortPointer(Index) doesn't fix anything. So, any idea what would cause a generic exception using a specified legal parameter on that function? I'm basically trying to render a heightmap via array buffers, but after spending hours figuring out what was wrong with the indexing, I got hung up on this Any help would be appreciated!
|
|
|
Post by Darkjester on Oct 23, 2013 21:05:43 GMT -5
Is it supposed to look like this? I changed "glDrawElements(GL_quads, size * size * 4, GL_UNSIGNED_SHORT, pInd)" to "glDrawElements(GL_quads, size * size * 4, GL_UNSIGNED_INT, pInd)" you defined "pInd" as "AllocBytePointer" and then tried to use the indices as a short, why? oddly though i was only able to get my above to work the one time to get that image. I have been unable to duplicate my success, perhaps this is a memory addressing problem with your plugin djlinux? edit: I have duplicated my success from earlier by changing dim MEM pInd=AllocBytePointer(Index) to dim MEM pInd=AllocIntPointer(Index) and doing what i posted above, have you checked your indices? second edit: was your intent to create 6 quads? as stated in your notes?
|
|
|
Post by shadow008 on Oct 25, 2013 15:50:54 GMT -5
No, I was simply modifying the "test04.gb" to get a test of the concept working. Forgot to change out the extra commentation. That was what I was thinking was weird too, but I went on to say that even swapping AllocBytePointer for AllocShortPointer did nothing, so I figured that wasn't the real problem. Your fix does work. However, I was hoping to do something at the size of 64x64 on the grid, which is too much for int's capacity. Following what you had, I changed "AllocIntPointer(Index)" to "AllocShortPointer(Index)" and swapped "GL_UNSIGNED_INT" for "GL_UNSIGNED_SHORT", as I figured that would iron everything out, yet the error persists. So it looks like the problem most likely lies in AllocShortPointer(). But that may not be the case, because throwing something like... ... dim MEM pInd=AllocShortPointer(Index) SetShort(pInd, 10, 11223) printr "Index value at 10 is : " + getShort(pInd, 10) drawText() while not Scankeydown(VK_RETURN) wend ...
...in seems to work just fine. I wonder if there's some conflict with the way glDrawElements accesses memory vs how the plugin does so... Maybe more specifically, whatever is called when GL_UNSIGNED_SHORT is the third flag. I really don't know at this point. I guess I could just call it good at 32x32, but... EDIT: So having two instances of B4GL open, both with the same lines of allocation, and switching between running one, and then the other without making sure "FreePointer" is called every time is bad. Don't do it. It doesn't fix the exception, but it fixes weird indexing errors, and I can now do what I wanted it to...
|
|
|
Post by Darkjester on Oct 26, 2013 20:03:37 GMT -5
strange errors indeed
|
|
|
Post by DJLinux on Nov 17, 2013 13:40:16 GMT -5
If you work with memory poiners you have to know what are you doing or it will crash. Do you got it working now ? DJ const SIZE = 16 const NITEMS = SIZE * SIZE
dim i, j dim Rot#
dim vert# ((size+1) * (size+1)-1)(2) dim Index% ((size+1) * (size+1)-1)(3) dim Colors#((size+1) * (size+1)-1)(2)
dim x,y for x = 0 to size' - 1 for y = 0 to size' -1 Vert#((x * (size + 1)) + y)(0) = y-SIZE/2.0 Vert#((x * (size + 1)) + y)(1) = 0 Vert#((x * (size + 1)) + y)(2) = x-SIZE/2.0 Colors#( (x * (size + 1)) + y) (0)=cos(x*(1.0/size)) Colors#( (x * (size + 1)) + y) (1)=sin(y*(1.0/size)) Colors#( (x * (size + 1)) + y) (2)=sin(sqr(x*x+y*y)) next next
for x = 0 to size -1 for y = 0 to size - 1 'Index( Index%((x * size) + y)(0) = (x * size) + y + x Index%((x * size) + y)(1) = (x * size) + y + 1 + x Index%((x * size) + y)(2) = ((x+1) * size) + y + 2 + x Index%((x * size) + y)(3) = ((x+1) * size) + y + 1 + x next next
dim MEM pVer=AllocFloatPointer(Vert#) dim MEM pCol=AllocFloatPointer(Colors#) dim MEM pInd=AllocIntPointer(Index%)
glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) glVertexPointer(3, GL_FLOAT, 0, pVer) glColorPointer(3,GL_FLOAT, 0, pCol)
glClearColor(.5,.7,.1,1)
'glMatrixMode(GL_PROJECTION) : glLoadIdentity()
'glMatrixMode(GL_MODELVIEW) : glLoadIdentity() gluLookAt(0,32,15, 0,0,0, 0,1,0)
while inkey$()="" glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glPushMatrix() glDrawElements(GL_QUADS, size*size*4, GL_UNSIGNED_INT, pInd) glPopMatrix()
SwapBuffers() WaitTimer(1000/50) Rot#=Rot#+1
if Mouse_Button(MOUSE_LBUTTON) then glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) endif wend
glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY)
|
|
|
Post by shadow008 on Nov 17, 2013 14:34:05 GMT -5
Yeah, I got it working. It was a problem on my part having multiple instances of the same program running at the same time.
On a tangent, utilizing glNormalPointer with glDrawElements and any sort of lighting enabled (be it fixed function lighting or shaders that call gl_Normal), results in a generic crash.
I've already gotten around it by simply passing the normals through glColorPointer and changing the variable in the shaders.
Here's an example:
dim LightPos#(3) sub InitOpenGL() dim MaxVertex,MaxIndex glGetIntegerv(GL_MAX_ELEMENTS_VERTICES,MaxVertex) glGetIntegerv(GL_MAX_ELEMENTS_INDICES ,MaxIndex) if MaxVertex<1 or MaxIndex<1 then print "sorry no support for elements" beep():end end if glLoadIdentity() gluLookAt(0,5,-20, 0,0,0, 0,1,0) end sub
' cube ' v6----- v5 ' /| /| ' v1------v0| ' | | | | ' | |v7---|-|v4 ' |/ |/ ' v2------v3
' 8 vertices data 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1 data 1,-1,-1, 1, 1,-1, -1, 1,-1, -1,-1,-1 ' 6 colors data 1, 0, 0 data 0, 1, 0 data 0, 0, 1 data 1, 1, 0 data 0, 1, 1 data 1, 0, 1
' 6 quads data 1,2,3,0 data 0,3,4,5 data 5,4,7,6 data 6,7,2,1 data 6,1,0,5 data 2,7,4,3
InitOpenGL()
dim Ver#(8*3-1) dim Col#(6*3-1) dim Ind(6*4-1) dim Norm#(8*3-1)'(8-1)(2) dim temp#(2) dim i for i=0 to 8*3-1 read Ver#(i) next for i=0 to 6*3-1 read Col#(i) next for i=0 to 6*4-1 read Ind(i) next
'Calculate normals as perpendicular to the verticies of the cube for i = 0 to 8*3-1 step 3 Norm#(i) = Ver#(i) Norm#(i+1) = Ver#(i + 1) Norm#(i+2) = Ver#(i + 2) temp# = Normalize(vec3(Norm#(i), Norm#(i+1), Norm#(i+2))) Norm#(i) = temp#(0) Norm#(i+1) = temp#(1) Norm#(i+2) = temp#(2) next
' create 2 float and 1 byte pointer dim MEM pVer=AllocFloatPointer(Ver#) dim MEM pCol=AllocFloatPointer(Norm#) dim MEM pInd=AllocShortPointer(Ind) dim MEM pNor=AllocFloatPointer(Norm#)
dim Rot# ' activate and specify pointers glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glVertexPointer(3, GL_FLOAT, 0, pVer) glColorPointer(3,GL_FLOAT, 0, pCol) glNormalPointer(3, GL_FLOAT, pNor)
'Enable for crash 'glEnable(GL_LIGHTING) 'glEnable(GL_LIGHT0)
while inkey$()="" glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) glPushMatrix() glScalef(5,5,5) glRotatef(Rot#, 0.5,0.25,0.125) ' draw 6 quads with 24 coords from index array glDrawElements(GL_QUADS, 24, GL_UNSIGNED_SHORT, pInd) glPopMatrix()
SwapBuffers() WaitTimer(1000/50) Rot#=Rot#+1 wend glDisableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_VERTEX_ARRAY)
Enabling the lighting at lines 91 & 92 causes glDrawElements to simply flop over.
|
|
|
Post by DJLinux on Nov 17, 2013 15:06:10 GMT -5
a nice shape only for fun DJ const SIZE = 32 const NITEMS = (SIZE+1) * (SIZE+1)
dim i, j dim Rot#
dim Vert# (NITEMS-1)(2) dim Index% (NITEMS-1)(3) dim Colors#(NITEMS-1)(2)
dim x,z,zind,ind
for z = 0 to size for x = 0 to size ind=zind+x Vert#(ind)(0) = x-SIZE/2.0 Vert#(ind)(1) = sqr((x-SIZE/2.0) * (z-SIZE/2.0)) Vert#(ind)(2) = z-SIZE/2.0
Colors#(ind) = Normalize(Vert#(ind))
next zind=zind+(size + 1) next zind=0 for z = 0 to size -1 for x = 0 to size - 1 ind=zind+x+z Index%(ind)(0) = ind Index%(ind)(1) = ind + 1 Index%(ind)(2) = ind+size + 2 Index%(ind)(3) = ind+size + 1 next zind=zind+size next
dim MEM pVer = AllocFloatPointer(Vert#) dim MEM pCol = AllocFloatPointer(Colors#) dim MEM pInd = AllocIntPointer(Index%)
glEnableClientState(GL_VERTEX_ARRAY) : glVertexPointer(3, GL_FLOAT, 0, pVer) glEnableClientState(GL_COLOR_ARRAY ) : glColorPointer (3, GL_FLOAT, 0, pCol)
glClearColor(.5,.7,.1,1)
gluLookAt(0,32,32, 0,0,0, 0,1,0)
while inkey$()="" glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glPushMatrix() glRotatef(rot# ,1,1,1) glDrawElements(GL_QUADS, NITEMS*4, GL_UNSIGNED_INT, pInd) glPopMatrix()
SwapBuffers() WaitTimer(1000/50) Rot#=Rot#+1
if Mouse_Button(MOUSE_LBUTTON) then glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) endif wend
glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY)
|
|