Skip to main content
GameDev.net gamedev.net
🔒 Locked

glDrawPixels

Started by Flash3r Jan 28, 2005 at 1:53 PM 2 replies 4k views
Original Post
Flash3r
Flash3r
Here is some background before my question. I am calculating and drawing a mandelbrot fractal in orthographic projection mode. My problem was that if I created a window and drew the fractal image at a ratio that was a multiple of 100 and ratio 1:1 (i.e. 600x600) the image would be fine, but if I drew it as other then that (i.e. 600x700 or 601x601) it would be completly corrupted. Also the fractal would be oriented wrong. It would be pointing down rather then to the left. I solved this by switching from using glDrawPixels() to just drawing each pixel one at a time: glBegin(GL_POINTS) for all points glColor3f glVertex2f glEnd Any reason why glDrawPixels was doing such weird things?
Enigma
Enigma
I would suspect that this problem is due to a DWORD alignment requirement on each row of pixels. That means that glDrawPixels probably requires each row of pixels to start at an address which is a multiple of 4 bytes. If you provide RGB byte data then a row of 100 pixels will result in each row taking up 300 bytes, which is a multiple of 4, so the next row will begin on a 4 byte boundary and everything will be OK. If however your rows are 101 pixels wide then each row will take up 303 bytes, which is not a multiple of 4. glDrawPixels will then skip a byte and source the next row beginning at the next 4 byte boundary, in this case ignoring the first red byte of the second row and treating the green byte as red, the blue byte and green and the red byte for the second pixel of the second row as the blue byte for the first pixel of the second row, etc. This results in the colours being corrupted on two out of three lines and the entire image being skewed slightly.

Enigma
jaba
jaba
I think this can be a good solution:
You can create a 1024x1024 texture and then update a portion of this (600x700)with glTexSubImage2D. To visualize create a quad textured with it.
Very easy and faster!!
I use this to visualize the video from webcams

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.