Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
void plotPixle(int x, int y, unsigned char color) {
/*
Plot a pixle in a certain color to the screen
Parameters
----------
x : int
The x position of the pixle
y : int
The y position of the pixle
color : unsigned char
The color inputted in hexadecimal
*/
switch (mbi->framebuffer_bpp) {
case 8:
for (int i = 0; i < 4; i++) { framebuffer[mbi->framebuffer_pitch * y + 1 * x + i] = 4; }
for (int i = 0; i < 4; i++) { framebuffer[mbi->framebuffer_pitch * (y + i) + 1 * x] = 4; }
break;
case 15:
break;
case 16:
for (int i = 0; i < 4; i++) { framebuffer[mbi->framebuffer_pitch * y + 2 * x + i] = color; }
break;
case 24:
for (int i = 0; i < 4; i++) { framebuffer[mbi->framebuffer_pitch * y + 3 * x + i] = color; }
break;
case 32:
for (int i = 0; i < 4; i++) { framebuffer[mbi->framebuffer_pitch * y + 4 * x + i] = color; }
break;
default:
// error
break;
}
}
Changing the color value between 0-255 changes how bright it is. Anything above 255 does not work.
Nearly everything about the code you posted is wrong. You are passing color as an unsigned char, so of course it only accepts values from 0-255. Anything else will wrap around and stay in that range. The logic for every single one of your bpp switch cases is wrong. I have no idea what you're trying to do but none of it makes sense. The one that is closest to being reasonable is the 32bpp case, but you are still assigning the same value to every channel and are only ever going to get shades of gray because of that. In all of the other cases, you are just completely wrong and I can't even begin to understand what you think you're doing.
klange wrote:Nearly everything about the code you posted is wrong. You are passing color as an unsigned char, so of course it only accepts values from 0-255. Anything else will wrap around and stay in that range. The logic for every single one of your bpp switch cases is wrong. I have no idea what you're trying to do but none of it makes sense. The one that is closest to being reasonable is the 32bpp case, but you are still assigning the same value to every channel and are only ever going to get shades of gray because of that. In all of the other cases, you are just completely wrong and I can't even begin to understand what you think you're doing.
Yeah no I just figured it out and I am so sorry. I completely misunderstood what it was doing. Sorry for the mistake.