亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gamedev_net - the simple directmedia layer from a win32 perspective, part 2 sdl video.htm

?? 好書,關于游戲開發數據結構的,還有一些實用例子
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
    if ( SDL_PollEvent ( &event ) )
    {
      //an event was found
      if ( event.type == SDL_QUIT ) break ;
    }
  }//end of message pump

  //done
  return ( 0 ) ;
}
</PRE></BLOCKQUOTE>
<P>This is our basic shell application for SDL, and during this TGO, we will 
build on it. As you can see, I already have initialized SDL's video subsystem 
with my call to SDL_Init, and I have already set the video mode (it is currently 
set up for windowed mode and uses the current display format).</P>
<P>This application doesn't do a whole lot, other than give you a blank, black 
window with a border around it. You can't resize the window, but you can move it 
around. This program simply waits for you to quit. However, I will point out 
that the equivalent application in GDI or DirectDraw would be about five times 
as many lines as we have here.</P>
<P>Now we've got to make the application actually DO something. Let's get to 
work.</P>
<H2>Rectangular Fills</H2>
<P>Often, you will need a large rectangular area of a surface cleared out to a 
particular color. The rectangular area can be as small as a single pixel, or as 
large as the entire screen. The function for doing this is SDL_FillRect.</P>
<BLOCKQUOTE><PRE class=code>int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
</PRE></BLOCKQUOTE>
<P>This function takes three parameters: a pointer to the destination surface, a 
pointer to an SDL_Rect that describes the rectangle you wish to fill, and a 
color (in the native pixel format of the surface). If you want to clear out the 
entire surface, you can use NULL for the dstrect parameter.</P>
<P>The surface we've got, and an SDL_Rect is easy enough to fill out. One thing 
we need before we can use this function is the ability to convert from a device 
independent color (i.e. an SDL_Color variable) into the native pixel format (and 
I don't want to use the code we looked at for this purpose earlier).</P>
<P>Luckily, SDL has such a function. It is called SDL_MapRGB.</P>
<BLOCKQUOTE><PRE class=code>Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b);
</PRE></BLOCKQUOTE>
<P>This function takes a pointer to an SDL_PixelFormat structure, and a red, 
green, and blue component from 0-255, and it figures out what value works for a 
native pixel of that same color (or the nearest equivalent).</P>
<P>So, let us say we want to fill the screen with pure red. This is how we'd go 
about it:</P>
<BLOCKQUOTE><PRE class=code>SDL_FillRect ( pSurface , NULL , SDL_MapRGB ( pSurface-&gt;format , 255 , 0 , 0 ) ) ;
</PRE></BLOCKQUOTE>
<P>But we're still not done. SDL's video system doesn't automatically display 
any of the changes to the surface. In order to make the new data visible, we 
have to update the rectangle. The function for doing this is SDL_UpdateRect.</P>
<BLOCKQUOTE><PRE class=code>void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
</PRE></BLOCKQUOTE>
<P>This function takes four parameters: the pointer to the surface, and an x , 
y, w, and h values describing the rectangle to update. If you wish to update the 
entire surface, you can place 0 into each of x, y, w, and h, like so:</P>
<BLOCKQUOTE><PRE class=code>SDL_UpdateRect ( pSurface , 0 , 0 , 0 , 0 ) ;
</PRE></BLOCKQUOTE>
<P>So, let's do a quick example. Start a new project named SDLRandomFillRect (or 
whatever you want to call it), set it up for SDL, and put the following code 
into main.cpp:</P>
<BLOCKQUOTE><PRE class=code>#include "SDL.h"
#include &lt;stdlib.h&gt;

enum {
  SCREENWIDTH = 512,
  SCREENHEIGHT = 384,
  SCREENBPP = 0,
  SCREENFLAGS = SDL_ANYFORMAT
} ;

int main( int argc, char* argv[] )
{
  //initialize systems
  SDL_Init ( SDL_INIT_VIDEO ) ;

  //set our at exit function
  atexit ( SDL_Quit ) ;

  //create a window
  SDL_Surface* pSurface = SDL_SetVideoMode ( SCREENWIDTH , SCREENHEIGHT ,
                                             SCREENBPP , SCREENFLAGS ) ;

  //declare event variable
  SDL_Event event ;

  //message pump
  for ( ; ; )
  {
    //look for an event
    if ( SDL_PollEvent ( &amp;event ) )
    {
      //an event was found
      if ( event.type == SDL_QUIT ) break ;
    }

<B>    //set up random rectangle
    SDL_Rect rect ;
    rect.x = rand ( ) % ( SCREENWIDTH ) ;
    rect.y = rand ( ) % ( SCREENHEIGHT ) ;
    rect.w = rand ( ) % ( SCREENWIDTH - rect.x ) ;
    rect.h = rand ( ) % ( SCREENHEIGHT - rect.y ) ;

    //fill the rectangle
    SDL_FillRect ( pSurface , &amp;rect ,
                   SDL_MapRGB ( pSurface-&gt;format , rand ( ) % 256 ,
                                rand ( ) % 256 , rand ( ) % 256 ) ) ;

    //update the screen
    SDL_UpdateRect ( pSurface , 0 , 0 , 0 , 0 ) ;
</B>  }//end of message pump

  //done
  return ( 0 ) ;
}
</PRE></BLOCKQUOTE>
<P>The lines in bold are new to this example (as opposed to the base shell 
code), if you just want to add those. Most of the lines are fairly obvious. Five 
of them deal with setting up the SDL_Rect variable, another does the filled 
rectangle, and yet another updates the display. On my display, this example runs 
really fast, but I've got a good video card and that's to be expected. Its 
output looks something like Figure 1.</P>
<P class=maintext-2 align=center><IMG height=409 
src="GameDev_net - The Simple DirectMedia Layer from a WIN32 Perspective, Part 2 SDL Video_files/02-01.jpg" 
width=518> <BR><B>Figure 1: Random FillRect Example Program</B></P>
<P>Filling rectangular areas in SDL is a lot simpler than the equivalent GDI or 
DirectDraw code (no HBRUSH to make, no DDBLTFX structure to fill out). Just give 
it a rectangle, a format, and color, and you've drawn yourself a rectangle.</P>
<H2>Pixel Plotting</H2>
<P>In theory, you could draw pixels using SDL_FillRect, and just use a w and h 
of 1. That, of course, is not how the SDL_FillRect function is intended to be 
used, but the SDL Police won't come and stop you, and it *IS* a completely cross 
platform method of drawing pixels, whereas doing pixel plotting with direct 
memory access can have portability issues, as we shall see in a moment.</P>
<P>In DirectDraw, in order to start writing to the memory of a surface itself, 
you need to Lock the surface and Unlock it when you are done. The same is true 
for SDL, in general. Some surfaces never need to be locked, typically those that 
dwell in system memory.</P>
<P>How do you tell? SDL provides a macro for you called SDL_MUSTLOCK. To test a 
surface, you do the following:</P>
<BLOCKQUOTE><PRE class=code>if ( SDL_MUSTLOCK ( pSurface ) )
{
//surface must be locked for access
}
else
{
//no need to lock surface
}
</PRE></BLOCKQUOTE>
<P>If you don't need to lock a surface, you will typically do nothing special, 
and so the entire else clause above won't be there.</P>
<P>In order to lock a surface, you call SDL_LockSurface. In order to unlock a 
surface, you call SDL_UnlockSurface. I doubt either function name comes as a big 
surprise to you. The same sort of caveats exist for SDL locks as for DirectDraw 
locks. Don't lock a surface longer than you have to, and don't call any system 
functions while a surface is locked. Treat the locked surface time as a critical 
section of your code's execution. Here are the prototypes for SDL_LockSurface 
and SDL_UnlockSurface.</P>
<BLOCKQUOTE><PRE class=code>int SDL_LockSurface(SDL_Surface *surface);
void SDL_UnlockSurface(SDL_Surface *surface);
</PRE></BLOCKQUOTE>
<P>Each of these have only one parameter... the pointer to the surface you 
intend to lock. In the case of SDL_LockSurface, there is a return value. If all 
goes well, this return value will be 0. If there is some sort of problem, you 
will get -1 instead.</P>
<P>Something important to point out here. You can lock a surface more than once 
prior to unlocking it. If you do this, you need to have as many unlock calls as 
you have lock calls, like so:</P>
<BLOCKQUOTE><PRE class=code>SDL_LockSurface ( pSurface ) ;    //first lock
SDL_LockSurface ( pSurface ) ;    //second lock
SDL_UnlockSurface ( pSurface ) ;  //first unlock... surface is still locked
SDL_UnlockSurface ( pSurface ) ;  //second unlock... surface is now unlocked
</PRE></BLOCKQUOTE>
<P>This is just something to be aware of. Generally speaking, if you have a 
large operation that requires some sort of direct access to the pixels of a 
surface, do a lock, do the operation, and do the unlock. If you have an even 
larger operation that relies on other operations that lock and unlock the 
surface, that's ok, because locking and unlocking is recursive.</P>
<P>Once the surface is locked, you can begin to directly access the pixel data 
through the SDL_Surface's pixels member. This includes working with the pixel 
format of the surface as well as the pitch member of the surface.</P>
<P>When setting pixels, I personally like to work with a pixel format 
independent representation of the color, i.e the SDL_Color structure, or 
something very much like it. I like having red, green, and blue all represented 
by numbers between 0 and 255. Unfortunately, an SDL_Surface can have a variety 
of different formats, and so we'll need to convert from an SDL_Color structure 
into the native format using SDL_MapRGB. No big deal.</P>
<P>From there, next need to know where exactly to write to. The pixels member of 
SDL_Surface is a void*. I personally like to convert it to a char*, and work the 
on the surface as though it were like a character buffer.</P>
<P>The offset from the beginning of the pixels pointer depends on the x and y 
coordinates of the pixel you wish to set. For every value in y, you increase by 
the contents of the SDL_Surface's pitch member. For every value in x, you 
increase by the contents of the SDL_Surface's pixel format's BytesPerPixel 
member. Calculating the position looks something like the following.</P>
<BLOCKQUOTE><PRE class=code>//point to beginning of buffer
char* pPosition = ( char * ) pSurface-&gt;pixels ;

//increment y
pPosition += ( y * pSurface-&gt;pitch ) ;

//increment x
pPosition += ( x * pSurface-&gt;format-&gt;BytesPerPixel ) ;

//pPosition now points to the proper pixel
</PRE></BLOCKQUOTE>
<P>We've got the proper position, and we've got the proper color. The only thing 
left is to copy the data from the color over into the buffer. This is where we 
meet a very small portability issue.</P>
<P>On WIN32 ( and many other operating systems), we can simply do the following 
code to copy the pixel data from the color variable into the buffer:</P>
<BLOCKQUOTE><PRE class=code>memcpy ( pPosition , &amp;color , pSurface-&gt;format-&gt;BytesPerPixel ) ;
</PRE></BLOCKQUOTE>
<P>And this will work, no problem, on most of the machines that the program is 
likely ever to be compiled for. But then there are the oddballs. The code above 
relies on the fact that the target machine is little endian. On a big endian 
system, unless using a 32 bpp surface, you are going to get garbled colors, or 
black. The solution? Well, I have one in mind, but I haven't had a chance to 
test it out yet ( since I don't have a machine that supports SDL but has a big 
endian). The basic idea is that you want to reverse the order of the bytes in 
the color variable if the machine is big endian, and then do the writing. There 
are a few macros and functions in SDL that can assist with this.</P>
<P>So, here's a basic putpixel function. This function assumes that the surface 
has already been locked, or does not need locking.</P>
<BLOCKQUOTE><PRE class=code>void SetPixel ( SDL_Surface* pSurface , int x , int y , SDL_Color color ) 
{
  //convert color
  Uint32 col = SDL_MapRGB ( pSurface-&gt;format , color.r , color.g , color.b ) ;

  //determine position
  char* pPosition = ( char* ) pSurface-&gt;pixels ;

  //offset by y
  pPosition += ( pSurface-&gt;pitch * y ) ;

  //offset by x
  pPosition += ( pSurface-&gt;format-&gt;BytesPerPixel * x ) ;

  //copy pixel data
  memcpy ( pPosition , &amp;col , pSurface-&gt;format-&gt;BytesPerPixel ) ;
}
</PRE></BLOCKQUOTE>
<P>To retrieve a pixel, we can recycle much of our pixel setting code, because 
the task is simply reversed. We determine the position in the exact same way, we 
memcpy it into a Uint32 variable (with the same minor caveat about big endians), 
and then convert it to an SDL_Color variable. The function for doing that is 
SDL_GetRGB.</P>
<BLOCKQUOTE><PRE class=code>void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b);
</PRE></BLOCKQUOTE>
<P>This function is much the same as SDL_MapRGB, except that this time, we send 
pointers to Uint8s into which are placed the various color components 
corresponding to the native pixel color. So, if we have a Uint32 variable called 
col, and an SDL_Color variable called color, this is how we would convert 
it.</P>
<BLOCKQUOTE><PRE class=code>SDL_GetRGB ( col , pSurface-&gt;format , &amp;color.r , &amp;color.g , &amp;color.b ) ;
</PRE></BLOCKQUOTE>
<P>And with that, we can make a GetPixel function.</P>
<BLOCKQUOTE><PRE class=code>SDL_Color GetPixel ( SDL_Surface* pSurface , int x , int y ) 
{
  SDL_Color color ;
  Uint32 col = 0 ;

  //determine position
  char* pPosition = ( char* ) pSurface-&gt;pixels ;

  //offset by y
  pPosition += ( pSurface-&gt;pitch * y ) ;

  //offset by x
  pPosition += ( pSurface-&gt;format-&gt;BytesPerPixel * x ) ;

  //copy pixel data
  memcpy ( &amp;col , pPosition , pSurface-&gt;format-&gt;BytesPerPixel ) ;

  //convert color
  SDL_GetRGB ( col , pSurface-&gt;format , &amp;color.r , &amp;color.g , &amp;color.b ) ;
  return ( color ) ;
}
</PRE></BLOCKQUOTE>
<P>And now time for another example. Create a project, and call it something 
like SDLRandomPixels. Place the following code into main.cpp.</P>
<BLOCKQUOTE><PRE class=code>#include "SDL.h"

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日产欧美一区| 亚洲午夜在线观看视频在线| 国产欧美日韩在线观看| 国产精品久久精品日日| 一区二区三区在线观看网站| 免费成人美女在线观看.| 免费成人av在线| 国产成人免费高清| 欧美日韩激情一区| 久久久久久久久久久电影| 亚洲女同ⅹxx女同tv| 蜜桃久久久久久| kk眼镜猥琐国模调教系列一区二区| 欧美无人高清视频在线观看| 欧美va亚洲va在线观看蝴蝶网| 成人欧美一区二区三区| 免费不卡在线观看| 欧美日韩一区二区三区视频| www国产亚洲精品久久麻豆| 亚洲高清免费在线| 国产成人日日夜夜| 日韩午夜三级在线| 亚洲午夜国产一区99re久久| 国产91丝袜在线观看| 色天使色偷偷av一区二区| 精品久久久久久最新网址| 亚洲一区二区三区中文字幕 | 麻豆91精品91久久久的内涵| 久久av资源网| 777精品伊人久久久久大香线蕉| 成人欧美一区二区三区视频网页| 性感美女极品91精品| 不卡一区在线观看| 欧美精品一二三区| 亚洲愉拍自拍另类高清精品| www.av精品| 国产欧美精品一区二区色综合| 午夜激情久久久| 欧美优质美女网站| 久久色.com| 免费观看一级特黄欧美大片| 色综合天天综合狠狠| 国产精品久久久爽爽爽麻豆色哟哟| 久久国产乱子精品免费女| 3d成人h动漫网站入口| 亚洲一区影音先锋| 在线视频亚洲一区| 一区二区三区在线观看网站| 91视频免费观看| 亚洲国产经典视频| 国产一区二区伦理| 久久久久久久久久久黄色| 国产麻豆成人精品| wwww国产精品欧美| 国产69精品一区二区亚洲孕妇| 51久久夜色精品国产麻豆| 午夜伊人狠狠久久| 欧美一区二区三区视频| 热久久久久久久| 久久久久久免费| 久久99国产精品久久99果冻传媒| 精品久久一二三区| 成人小视频在线| 亚洲精选免费视频| 欧美日韩在线播放一区| 日欧美一区二区| 欧美电视剧免费观看| 青青草原综合久久大伊人精品 | 国产精品丝袜黑色高跟| 99久久777色| 亚洲一区在线观看视频| 欧美丝袜丝nylons| 久久精品999| 国产精品视频看| 在线亚洲免费视频| 日韩精品视频网| 久久亚洲综合色| 色天使久久综合网天天| 日韩二区三区在线观看| 亚洲国产精品精华液ab| 欧美综合色免费| 三级不卡在线观看| 国产免费观看久久| 欧美日产国产精品| 成人深夜在线观看| 午夜视频在线观看一区二区| 欧美福利视频一区| 成人一级黄色片| 天天av天天翘天天综合网 | 麻豆精品一区二区av白丝在线| 欧美成人女星排行榜| 色综合天天综合在线视频| 男女激情视频一区| 亚洲日本电影在线| 精品久久久久久久久久久久久久久久久| 国产盗摄女厕一区二区三区| 亚洲国产美女搞黄色| 国产欧美一区二区在线| 91精品国产一区二区三区| 国产成人亚洲综合色影视| 亚洲成人免费电影| 国产精品无人区| 精品久久久久久久久久久院品网| 高清不卡在线观看| 精品亚洲国产成人av制服丝袜| 亚洲综合另类小说| 亚洲综合成人在线视频| 一区二区三区四区五区视频在线观看 | av一区二区久久| 成人av电影在线网| 国产a视频精品免费观看| 九九久久精品视频| 国产sm精品调教视频网站| 精品在线播放免费| 极品美女销魂一区二区三区 | 国产日韩欧美激情| 国产亚洲人成网站| 国产网站一区二区三区| 26uuu精品一区二区三区四区在线| 欧美一区二区三区四区视频 | 欧美调教femdomvk| 欧美图区在线视频| 欧美精品v国产精品v日韩精品 | 日韩精品欧美成人高清一区二区| 亚洲久本草在线中文字幕| 亚洲三级免费观看| 亚洲国产日韩综合久久精品| 亚洲福利视频一区二区| 午夜精品一区二区三区电影天堂| 亚洲成精国产精品女| 日本伊人色综合网| 国产又黄又大久久| 99久久99久久免费精品蜜臀| 欧美色视频一区| 日韩精品一区国产麻豆| 26uuu精品一区二区| 综合色天天鬼久久鬼色| 亚洲一本大道在线| 国产在线播放一区| 91一区二区在线| 欧美一区二区三区视频免费 | 成人av集中营| 日本精品一区二区三区高清| 91精品国产综合久久精品| 国产亚洲综合色| 亚洲成年人影院| 国产丶欧美丶日本不卡视频| 欧美天堂一区二区三区| www激情久久| 亚洲在线成人精品| 国产一区二区三区四区五区入口| 色哦色哦哦色天天综合| 日韩欧美综合在线| 一区二区三区精品视频| 久久99久国产精品黄毛片色诱| gogo大胆日本视频一区| 91精品久久久久久久99蜜桃| 国产精品久久久久久久久久久免费看| 亚洲成人www| 91免费观看国产| 精品久久久久久无| 亚洲亚洲精品在线观看| 成人动漫中文字幕| 久久综合色天天久久综合图片| 综合欧美一区二区三区| 韩国毛片一区二区三区| 欧美日韩你懂的| 欧美国产禁国产网站cc| 日本中文一区二区三区| 色综合久久88色综合天天6| 久久久99久久精品欧美| 蜜臀av一级做a爰片久久| 欧美综合一区二区三区| 国产精品嫩草99a| 国产在线精品视频| 欧美一级夜夜爽| 亚洲一级电影视频| 99热在这里有精品免费| 久久午夜电影网| 久久se精品一区二区| 欧美久久久一区| 天涯成人国产亚洲精品一区av| 成人激情黄色小说| 日本一区二区三级电影在线观看| 麻豆精品视频在线| 欧美久久一二三四区| 亚洲国产日韩综合久久精品| 色综合天天综合| 国产精品福利一区| 成人午夜激情视频| 91精品国产91综合久久蜜臀| 亚洲一区二区三区四区不卡| 99久久综合99久久综合网站| 国产肉丝袜一区二区| 久久国产成人午夜av影院| 欧美一区二区三区啪啪| 五月天国产精品| 欧美一区二区高清| 日本免费在线视频不卡一不卡二| 欧美日韩国产片|