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
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.
* 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:
At this point, anything I draw is not drawn to the screen but to the biggo virtual screen so when I use:
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:
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).
~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.
To 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).
Now, 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
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$()=" "
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
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.
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
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 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
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?
Last Edit: Oct 24, 2013 18:52:43 GMT -5 by Darkjester
second edit: was your intent to create 6 quads? as stated in your notes?
No, I was simply modifying the "test04.gb" to get a test of the concept working. Forgot to change out the extra commentation.
you defined "pInd" as "AllocBytePointer" and then tried to use the indices as a short, why?
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...
Last Edit: Oct 25, 2013 16:27:33 GMT -5 by shadow008
Warning: boredom may result in armed robbery, kidnapping, reckless endangerment of others, aggravated assault of a police officer, felony fleeing apprehension, and damage to property.
We should take bikini bottom, and push it somewhere else! <(O.O<) <(O.O)> (>O.O)>
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%)
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
' 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
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()
dim Vert# (NITEMS-1)(2) dim Index% (NITEMS-1)(3) dim Colors#(NITEMS-1)(2)
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%)