calculate X and Y for an array need help

hi this is no advanced stuff i guess but i do not understand it :frowning:

i have a 1 dimension array wich holds pixels (just black pixels)

so i have something like 600 fields in this array it is a 20x30px image right

i need to calculate the number in the array where a pixel is . given the X and Y coordinates… how can i do this?

wuld a 2d array be better? (guess so but im forced to use 1d).


if you have an array

float pixels[32030];

and want to address position X/Y:

pixels[3*(20Y+X)+0] = red_component;
(20Y+X)+1] = green_component;
(20*Y+X)+2] = blue_component;

(assuming 20 is the size in x-direction)

danke danke!!!
do you have any links where i can learn about maths and stuff like this ? if its not much to ask :slight_smile:

gern geschehen :wink:

i think wolframresearch is a good address for basic and advanced mathematics.

uh i dunno whats wrong but here is what i had

my array is made like this


it is an integer array it has hex values in it!

so should i do:


to get the hex (pixel) in that X and Y coords???
or what?

your exampel works i guess but im using hex on long integers :frowning:

what i got is just a mess of colors (kinda like a pattern :s ) i dunno what to do :frowning:

i tried a source to source type of test i read this way and put the data back in place but oh well the image looks like crap (just a dashed line pattern) hmm

im usin a real image to test now so that is what i get :frowning:

Hex,Octal,Decimal is only applied to constants in programming languages and are automatically converted to the machine number format, which will probably be binary… Dereferencing an array element does not depend on such compile-time stuff.
Of course it is important what type of elements the array sports for passing the array to opengl for example. You will have to tell us which color format you specify during texture upload to help us help you.


thank u all

my question is not really about opengl so sorry im really sorry but you guys know how to do this so i asked here and not somewhere elses!

i have an array wich has all the pixels of an image inside

i know the width and the height of this image
the data inside the array is simply integers.

how can i get the pixel at X=100 and Y = 30 for example? knowing that i have the width, height on a 1D array full of pixels (each item a pixel).


alrite im so stupit sometimes
it is my dyslexia that bothers me a lot :frowning:

i just had to add the width to the Y value …

well i think i got it but in case i didnt can someone correct me if this is wrong what i just said ??

nopes didnt got it :frowning: help me plz

  • how many color components do you have by pixel ?
  • is your image in an uncompressed format ?
  • can you post the part of the code you are working on ?

I currently seek a bookshop graphic which can draw me curves like the fft or a simple function. one of my friends my proposed openGL I know practically anything on this tool. could you indicate to me how I can work with this library knowing that I program with visual C++? thank you very much.