Hi,
I've made some progress. I can generate the color, but still can't generate the rectangle. Below is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
//drawPixel function
//added to simplify drawing loops below
void drawPixel(unsigned char *picPointer, int picWidth, int x, int y, unsigned char
rVal, unsigned char gVal, unsigned char bVal)
{
picPointer[3*y*picWidth + 3*x] = rVal; //+0 to access red byte
picPointer[3*y*picWidth + 3*x + 1] = gVal; //+1 to access green byte
picPointer[3*y*picWidth + 3*x + 2] = bVal; //+2 to access blue byte
return;
}
int main (int argc, char *argv[])
{
if (argc < 3)
{
fprintf(stderr, "Usage: %s width height\n", argv[0]);
exit(1);
}
const int wid = atoi(argv[1]);
const int ht = atoi(argv[2]);
unsigned char *picture = (unsigned char *) malloc(3*wid*ht*sizeof(unsigned char));
int x,y;
for(y=0;y<ht;y++)
{
for(x=0;x<wid;x++)
{
drawPixel(picture,wid,x,y,60,100,200); //fills whole image with a light blue
}
As always, any help is greatly appreciated.
Thanks.