Writing to screen buffer.

This is a discussion on Writing to screen buffer. within the Game Programming forums, part of the General Programming Boards category; Hallo, I am using a API which does not have any setPixel() functions, instead it just has a long array. ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Writing to screen buffer.

    Hallo,

    I am using a API which does not have any setPixel() functions, instead it just has a long array. Im trying to make my own setPixel() function, but im not really sure im doing it the right way.

    This is how I try to set the color of a pixel:
    Code:
    #define SCREEN_WIDTH	768
    #define SCREEN_HEIGHT	512
    #define BYTES_PER_PIXEL	4
    
    // yPos and xPos are integers.
    // Is this the correct calculation?
    int pixelOffset = BYTES_PER_PIXEL * ((yPos *  SCREEN_WIDTH)) + xPos);
    
    screen[pixelOffset ] = 255;
    screen[pixelOffset +1] = 255;
    screen[pixelOffset +2] = 255;
    //screen[pixelOffset +3] = 255; Alpha channel, not used
    Thanks for your time

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Looks OK to me - assuming of course you have the right byte-order and the pixels are organized in a linear order.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I am using a API which does not have any setPixel() functions, instead it just has a long array. Im trying to make my own setPixel() function, but im not really sure im doing it the right way.
    Does your code work and produce the expected output?
    Or are you having problems with it?
    What API are you using?
    Screen should be and unsigned character array, you probably already have it as such.
    If you arent drawing white pixels then your byte ordering is the wrong way around.
    If the code does not compile it could be that the screen is an object and the actual image buffer is contained within it.
    Your pixel offset calculation should be correct

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Thanks for the help.

    The API is called HAPI, it made by at teacher at the University. The problem had to do with the really really stupid way i was drawing pixels to the screen.
    Last edited by h3ro; 01-15-2008 at 05:32 PM.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by h3ro View Post
    Thanks for the help.

    The API is called HAPI, it made by at teacher at the University. The problem had to do with the really really stupid way is was drawing pixels to the screen.
    So HAPI is making you SAD. There's an irony for ya!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  2. How Can I.....(OpenGL)
    By Shamino in forum Game Programming
    Replies: 33
    Last Post: 06-01-2005, 06:31 AM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  4. accepting input while writing to screen
    By variable in forum C Programming
    Replies: 17
    Last Post: 02-06-2005, 09:14 PM
  5. drawing to screen
    By Noobie in forum C++ Programming
    Replies: 11
    Last Post: 02-27-2003, 03:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21