Skip to main content
gamedev.net
🔒 Locked

newbie question

Started by Joker2000 1 reply 250+ views
Original Post
Joker2000
Joker2000
I''ve been looking at all this Win32/DirectX programming and I just have to ask - what the hell does "(USHORT *)" do in the position that it''s in here: video_buffer = (USHORT *)ddsd.lpSurface; I''ve seen syntax like this before but I don''t know what exactly the (USHORT *) is doing there? Why in parentheses? Etc. etc. etc.
Michael Borromeo
Michael Borromeo
the (USHORT*) is just type casting the surface pointer. the reason this is done is because the variable video_buffer is probably a USHORT pointer. if the type cast wasnt there i think there would be a warning or something. at any rate basically its just telling the comp what kind of data your dealing with.
Ironblayde
Ironblayde
A cast is made on lpSurface because chances are, you''re going to want to be able to use array notation with video_buffer to access one pixel at a time on your surface. For instance, video_buffer[0] points to the first pixel on the screen, and video_buffer[1] points to the second. To achieve this, you must have a pointer of the right size. Since a USHORT is a 16-bit variable, you would cast lpSurface to a USHORT* if you were working in a 16-bit screen mode. Similarly, if you were using a 32-bit screen mode, you''d cast lpSurface to a UINT* instead.

-Ironblayde
 Aeon Software
"Your superior intellect is no match for our puny weapons!"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.