Using a Sprite as a Pixel Buffer

Previous topic - Next topic

ProN3rd

EDIT: solved it, i figured some pixel values were not set as INTEGERs, what caused the errors in the assignment to the array

I have been working on a portal based rendering graphics engine, like DukeNukem, Shadow Warrior and the like, where the screen gets renderened in vertical lines. For each x coordinate there are at least three y- lines (floor,main,ceiling), and often more when other sectors are seen through respective portals.

Everything works fine and smooth, until i started using the setpixel instruction instead of drawline. I figured out from the forum that setpixel does not use opengl and is quite slow therefore.

However to apply textures and lightning, i need individual pixel access, so i had the idea to write the pixels to a pixel buffer instead of drawing immediate points. I think this is also the way its done with SDL c++.

Anyway the following code works horrible. It works somehow and has quite good speed compared to setpixel but I can barley recognize the scene: between 50k and 70k pixels are lost out of 307.000 (640 x 480) and dont get rendered at all, it seems like.

How can i deal with this?

Code (glbasic) Select

GLOBAL W = 640, H = 480
LOADSPRITE "texture.png", 0  //640x480 dummy
GLOBAL pix%[];SPRITE2MEM(pix%[], 0);
MEM2SPRITE(pix%[], 1, W, H)  //work with this copy

WHILE TRUE
  CalculatePixels()  // All pixels get assigned in here
  MEM2SPRITE(pix%[],1,W,H)
  DRAWSPRITE 1, 0,0
  Showscreen
WEND

Hemlos

#1
Well, you are reading a very large array (307200 indices).
Also generating a large image, AND rendering it, in *every frame*, 640x480 is a bit excesive.

That is mistake #1 and #2, and #2.5

Mistake #3....depending on getpixel for accuracy....read the help file for more info on this, so you can better plan your next tests.

Also consider make your images a power of 2 in size eg 8x8 16x16 32x32 64x64 128x128, opengl seems to work more effectively with the right dimensions.


oh ya almost forgot....use polyvector command to get more speed with rendering 2d in glbasic.
you can even use it to make a pixel, or a line, plus you can fade colors across them, because they have color nodes for each corner vertex. i recently shared a bit of code that creates texturable stars, using polyvectors.
That project is in the 2d codesnippets section of the forums, http://www.glbasic.com/forum/index.php?topic=10411.0



ps. love your ideas, i tried that same exact thing many years ago.....in the end i built a program that generates 3d objects for glbasic, from an image as a template.
Its tricky though, and the current state of that code is a mess, and out of date....theoretically it still works.
its called image2object in the download section of www.glbasic.com
Bing ChatGpt is pretty smart :O

erico

Yep, I love this idea too, post a video of it running whenever you can, I (+ others I bet) would like to see it in action ;)