Lesson2 gfx.PutPixel

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Lesson2 gfx.PutPixel

Post by Asimov » May 20th, 2012, 5:09 pm

Hi Chilli,

I have just watched lesson 2 and I have a quick question about the gfx.PutPixel function. Is this just a function that is in your framework, or is it a function of Directx?

I am guessing it is either an inbuilt function in Directx, or you have written a function called gfx.PutPixel which talks to the directx api.

PS:
I haven't done the tutorial yet, just watched it. I would setup two integers for x and y, and then use offsets. You could then take this and make some kind of sprite class function, which would be in the form of something like:

Mysprite(100,200);
Which then could be placed anywhere on the screen.

I think later it would be possible to make a class to load in a png directly. Probably like SDL does.
Don't get me wrong I have used SDL on a previous project, but it is nice to know how to manipulate pixels on their own.

I like the style of your tutorials. I am not going to watch anymore until I got your framework installed.

Asimov

PPS. Just watched a little more. Who is Ron Paul. Bare in mind I live in Great Britain.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Lesson2 gfx.PutPixel

Post by LuX » May 21st, 2012, 10:36 am

Most of the stuff you talked about will come in later tutorials.
Is this just a function that is in your framework, or is it a function of Directx?
The PutPixel itself is a simplified version, but what is affects is Directx. you can go to the PutPixel in D3DGraphics and then select some words and press F12 to jump to its definition, which leads to microsofts own directx 3d header.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson2 gfx.PutPixel

Post by chili » May 21st, 2012, 10:54 am

Asimov wrote:I am guessing it is either an inbuilt function in Directx, or you have written a function called gfx.PutPixel which talks to the directx api.
It uses DirectX to gain direct access to the graphics memory and then changes the value of a pixel in the back buffer.

Ron Paul is an interesting political figure in the U.S.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Lesson2 gfx.PutPixel

Post by Asimov » May 21st, 2012, 5:19 pm

Hi Chilli,

Thanks for the great tutorials. I just deisigned, my own cross hair, which looks good heh heh.
Doing it this way reminds of the old UDGs on the Spectrum heh heh.

I do have another few questions about the framework.

When I used the SDL framework, I had to time everything that went to the screen, so that it run the same speed on all computers. I can't remember the exact command, but I could look it up.
I am guessing your framework already does this in the timer.cpp and the time.h file?

Also I notice that when I move my cross hair you don't get the flickering that I was expecting, so is it double buffereing before being sent to the screen?

I listened to your explanation of why there is a cpp file and a header file. I have programmed in C++ before and all the books put the constructor actually in the class itself. Putting the class in the header file and the constructor in the cpp is totally new to me. In the last program I wrote for SDL I did my entire Class, constructors and desconstructors in the header file. Is this a bad thing?

Does the framework do anti aliasing as standard, or does this need to be programmed in somewhere?

Once last question. I know I can increase the speed of the sprite by using larger increments of pixels as it is moving, but even at incrementation of 1 pixel I was expecting the sprite to move faster than this. I was expecting to have to use some kind of clock delay to slow it down. So the question is why isn't it as fast as I expected?

I hope you don't mind all these questions. I don't expect and answer to everything I ask, because I know you are a most probably a very busy person. I can't wait to watch more tutorials.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson2 gfx.PutPixel

Post by chili » May 22nd, 2012, 3:05 pm

Asimov wrote:When I used the SDL framework, I had to time everything that went to the screen, so that it run the same speed on all computers. I can't remember the exact command, but I could look it up.I am guessing your framework already does this in the timer.cpp and the time.h file?
There is no timing implemented at the moment. We will add that in at a later date. The Timer class was included with that purpose in mind (and for benchmarking as well).
Asimov wrote:Also I notice that when I move my cross hair you don't get the flickering that I was expecting, so is it double buffereing before being sent to the screen?
Yup, double buffering is being used.
Asimov wrote:I listened to your explanation of why there is a cpp file and a header file. I have programmed in C++ before and all the books put the constructor actually in the class itself. Putting the class in the header file and the constructor in the cpp is totally new to me. In the last program I wrote for SDL I did my entire Class, constructors and desconstructors in the header file. Is this a bad thing?
It's not that bad really. In fact, if you make template classes then you have no choice but to put the implementation in the header. I prefer putting as much in the .cpp as possible because it simplifies situations where two classes depend on each other mutually, and because it's cleaner. However, if you want to have the compiler inline a function, it has to be defined in the header file, so we will be doing some of that too.
Asimov wrote:Does the framework do anti aliasing as standard, or does this need to be programmed in somewhere?
Needs to be implemented by the user of the framework. The framework is just a skeleton that will will continually add to. There's really nothing to it at all, it's just a vehicle for teaching the basics of C without having to resort to boring old console mode. I will teach all the API and hardware know-how needed to write something like the framework in the near future.
Asimov wrote:Once last question. I know I can increase the speed of the sprite by using larger increments of pixels as it is moving, but even at incrementation of 1 pixel I was expecting the sprite to move faster than this. I was expecting to have to use some kind of clock delay to slow it down. So the question is why isn't it as fast as I expected?
The double buffering mode used synchronizes the page flip with the monitor refresh (to avoid tearing). Therefore, your frame rate is going to be capped at the refresh rate of your monitor (60 Hz for most people). Since the speed of the sprite is directly proportional to the frame rate, you speed is likewise capped as such. It is possible to unlock the frame rate from the monitor refresh, but there is not logical reason to do so. You do not get any benefit out of redrawing the scene at a higher frequency than the refresh rate of the monitor. Additionally, if you do not syncronize the page flip with the monitor VSYNC signal, you get ugly tearing artifacts.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Lesson2 gfx.PutPixel

Post by Asimov » May 22nd, 2012, 6:08 pm

Hi Chilli,

Thank you for your help. Over the years I have watched tutorials, but never have they been as clear as they are on here, and your accent is really clear.

Anyway you will laugh at this. As soon as I got to the tutorial about drawing a line. I decided to write my own line drawing function. For some reason whatever I did my lines always drew at a 45 degree angle, no matter where I put my points. Anyway after a full day of trying I decided to watch the next tutorial, and low and behold the whole tutorial is about making a line drawing function. I didn't realise how complex the maths were. Anyway I followed your tutorial to the end, and I understood most of it. I will say I am a little foggy on maths and it wasn't my best subject. I probably would have had trouble writing this part of the code on my own, but your tutorial was great. It's a long time since I have been at school, and this has been the most intensive maths lesson I have had for a number of years.

Yeh I have always suffered at school with poor maths teachers. I couldn't get to grips with binary arithmatic at school, but when I had to design my own udgs I taught myself from a book. Then later I learnt how to add and subtract and xor in binary, for programming LEDs. However I have now forgotten most of what I learnt years ago, due to the fact it is hardly used nowadays.

Now I am going to make a spirograph and post it in another thread heh heh.

Thank you (I bet you must be some kind of rocket scientist in your spare time).

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson2 gfx.PutPixel

Post by chili » May 23rd, 2012, 2:11 pm

Familiarity with binary notation and operations will serve you well in some future tutorials bro.

As for myself, I'm no rocket scientist. Just a lowly patent translator. ;)
Chili

Post Reply