I have an array that holds the ARGB values where each block of 4 represents a single pixel.
Of course the Alpha isn't actually copied into the video memory, but is just used to calculate blending between the color behind.
I have a struct called Object that I'm using to draw the shapes to the screen. This holds the objects size, location, background color, etc.
I re-draw the entire screen every second calling vesa_drawObjects(), which calls the objects_draw() for each of the objects and puts them into the buffer. Then after that's all done vesa_draw simply does a memcpy.
The issue is that for large objects with a size over 100(w)x100(h) it seems to put incorrect values into the vram or object_draw puts incorrect values into pixelData.
For example, with an object of 400x400 and a background color of blue, the top third will be blue then after that it turns white then it's just all random colors.
Here is a screenshot showing that example: http://imgur.com/a/nax6c
Code: Select all
// vesa.h
unsigned char buffer[1024 * 768 * 4]; // This is the buffer
// --
// vesa.c
// Don't shoot for terrible code
void vesa_drawObjects(Object *objs, long len) {
Object sortedObjects[len];
sortObjects(objs, sortedObjects, len); // This just re-orders the objects based upon zOrder
for(int i = 0; i < len; ++i) {
// ... SNIP ...
unsigned long bufSize = sortedObjects[i].size.Width * sortedObjects[i].size.Height * 4;
unsigned char pixelData[bufSize];
object_draw(pixelData, bufSize, sortedObjects[i]);
for(unsigned long p = 0; p < sizeof(pixelData) / sizeof(pixelData[0]); p += 4) {
unsigned long where = (x * (fb_width / fb_xres)) + (y * fb_width);
// buffer goes RGB but video memory goes BGR so gotta switch it around
buffer[where + 0] = pixelData[p + 2];
buffer[where + 1] = pixelData[p + 1];
buffer[where + 2] = pixelData[p + 0];
//buffer[where + 3] = pixelData[p + 3]; // Alpha
// ... SNIP ...
}
}
}
// --
// object.c
// More terrible code
void object_draw(unsigned char* buffer, unsigned long bufSize, Object obj) {
for(unsigned long p = 0; p < bufSize; p += 4) {
buffer[p + 0] = obj.backgroundColor.R;
buffer[p + 1] = obj.backgroundColor.G;
buffer[p + 2] = obj.backgroundColor.B;
buffer[p + 3] = obj.backgroundColor.A;
}
}
// --
Code: Select all
// pseudo code but you get the idea...
for(int y = 0; y < 400; ++y) {
for(int x = 0; x < 400; ++x) {
vram[where + 0] = 255;
vram[where + 1] = 0;
vram[where + 2] = 0;
}
}