Stuck in the introduction to C with game development part 8http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528
[This tutorial](http://devmaster.net/posts/2850/introduction-to-c-with-game-development-part-8-memory-addresses-and-pointers)
I understood everything up until part 8, the whole concept of pointers and pixels. This function in particular:
void Game::Tick( float a_DT )
{
Pixel* address = m_Screen->GetBuffer();
for ( int i = 0; i < 307200; i++ ) address[i] = i;
}
what is meant by adress and where does the i in address\*refer to? And could someone explain what Pixel\* does?
-
Fri, 04 Jan 2013 22:00:33 +0000general devStuck in the introduction to C with game development part 8no-reply@example.com (@TTTNL Ton)@TTTNL wrote:

Thanks! It took me some effort but the pieces are falling together. And i figured out how to make it dotted! By accident really but hey it works and because of that i get it.

]]>http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528/6
Fri, 04 Jan 2013 22:00:33 +0000post-22528-6Stuck in the introduction to C with game development part 8Stuck in the introduction to C with game development part 8no-reply@example.com (@fdmfdm Frank Dijkhuizen)@fdmfdm wrote:

well, the plot function would be a function that plots something, as obvious as it may sound, think about it. i take it you are dutch (considering your name) but you have had math at school, you probably used a graphic calculator there, on which you had to plot a function. a plotfunction seems nothing more then a function to calculate where and what should be placed on the screen.

but for assignment 1. the first step you want to do with something like this is think they want you to use a pointer variable after this tutorial, where did you use it earlier in this tutorial?

now you can say this is a plot function, but it is what they mean i think, because you are not pointing at a pixel, but at the loction of the pixel now lets think, they want you to go from 0,0 to 400,00. that meant everytime you go down 1 pixel, you will need to go 1 to the right as well. the standart screen is 640 in that tutorrial i think, so if you know how the array works for the pixels (it simply keeps going to the right, pixel 0 is the first one on the top left, pixel 1 is the second one, and pixel 639 is the last one on the top row. pizel 640 at the other hand is the first pixel on the second row,

or many other forms of code for the same thing, one is a bit faster then the other, but at this point i dont thing thats really important, its more important that you understand the concept now this is simply for a line from 0,0 to 400,400 think of a way to make it a dotted line, which is quite simple, if you can do that, you should understand the general concept good enough for this tutorial

if you still dont understand, you might want to check out #10 of that tutorial, which is about arrays

]]>http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528/5
Fri, 04 Jan 2013 13:26:42 +0000post-22528-5Stuck in the introduction to C with game development part 8Stuck in the introduction to C with game development part 8no-reply@example.com (@TTTNL Ton)@TTTNL wrote:

Thanks for the help, but could somebody explain assignment 1 of that tutorial? It still isn't really clear to me how to get those coordinates in the funciton. Also, what does the plot function mean?

DDraw a dotted line (skip every other dot) from (0, 0) to (400, 400). Do not use the Plotfunction, use a pointer variable instead. Figure out what the distance between dots in memory is to make this code super simple and fast.

]]>http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528/4
Fri, 04 Jan 2013 13:03:37 +0000post-22528-4Stuck in the introduction to C with game development part 8Stuck in the introduction to C with game development part 8no-reply@example.com (@v71 V71)@v71 wrote:

Maybe he has an hard time understanding how a linear array maps into a square frame buffer , actually the formula is pretty simple its is : x+y*ResX , where ResX is the horizontal resolution of your window. A lot of tricks can be performed when the pixel writing happens in loops, like precomputation to avoid an expensive multiplication inside a tight for loop. In the example abov you are simply filling all the buffer with a single color. Another fact is that you have 3 bytes for each color so actually you need a buffer which is 3 times wide and perform an aligned write in 3 consecutive bytes, but this is something you should inspect further after you have fully grasped the concept of mapping buffers with linear arrays , whichbasically points out to the earlier formula.

]]>http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528/3
Fri, 04 Jan 2013 11:57:34 +0000post-22528-3Stuck in the introduction to C with game development part 8Stuck in the introduction to C with game development part 8no-reply@example.com (@fdmfdm Frank Dijkhuizen)@fdmfdm wrote:

well, i have done that tutorial, and to be quite honest, it is not that important at this point to know where the i stands for, as arrays will come later, but to give you a general idea, it stands for which pixel you are asking the adress for, now your first question was what is meant by adress, it is simply the place where the information about that pixel is places, so is is really just the adress of the information. then the i, as said before it stands for which pixel you want. let take the screen of 640 by 480, that means you have 307200 pixels. you said that on the location of the pixel you wanted the informatiobn address

maybe that was not clear enough? lets just look at Pixel* Pixel* simply puts address as the location of writing, in this case in the buffer of your screen (so the screen you are drawing on, not the screen you are see at that moment (i trust you know by now how the drawing process works, it is explained somewhere in that tutorial not sure hwere) you have the for loop, which you must know how it works, and then in that loop stands

address[i] = i;

this is actually incredible simple if you know what a array is, and array is a collection of many variables with the same name. like: cookie[0] cookie[1] cookie[2]

this is a small array, but you use an array for the pixels on your screen, or rather for the address of the pixels on your screen (because a pointer points to a address) and it puts the value i on that location. thats why if you run this code you will see all pixels have different collors, to a certain extend. they will all be blueish if i remember right. this is because the way colors are put in the memory, but again this is something you will learn later.

so in short: the i refers to which pixellocation in the array is meant, and Pixel* points to the location of the Pixelarray, which you have never seen, but is somewhere in the screenfunction in the template

]]>http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528/2
Thu, 03 Jan 2013 11:59:00 +0000post-22528-2Stuck in the introduction to C with game development part 8Stuck in the introduction to C with game development part 8no-reply@example.com (@TTTNL Ton)@TTTNL wrote:

]]>http://forum.devmaster.net/t/stuck-in-the-introduction-to-c-with-game-development-part-8/22528/1
Thu, 03 Jan 2013 09:47:33 +0000post-22528-1Stuck in the introduction to C with game development part 8