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

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

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

?? 好書,關于游戲開發數據結構的,還有一些實用例子
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<B>#include &lt;stdlib.h&gt;
#include &lt;memory.h&gt;
</B>
enum {
  SCREENWIDTH = 512,
  SCREENHEIGHT = 384,
  SCREENBPP = 0,
  SCREENFLAGS = SDL_ANYFORMAT
} ;

<B>void SetPixel ( SDL_Surface* pSurface , int x , int y , SDL_Color color ) ;
SDL_Color GetPixel ( SDL_Surface* pSurface , int x , int y ) ;
</B>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>    //pick a random color
    SDL_Color color ;
    color.r = rand ( ) % 256 ;
    color.g = rand ( ) % 256 ;
    color.b = rand ( ) % 256 ;

    //lock the surface
    SDL_LockSurface ( pSurface ) ;

    //plot pixel at random location
    SetPixel ( pSurface , rand ( ) % SCREENWIDTH , rand ( ) % SCREENHEIGHT , color ) ;

    //unlock surface
    SDL_UnlockSurface ( pSurface ) ;

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

  //done
  return ( 0 ) ;
}
<B>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 ) ;
}
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 ) ;
}
</B></PRE></BLOCKQUOTE>
<P>Again, the code in bold is the code that has been added to the basic shell 
application. This example starts placing dots of random colors onto the window. 
When it runs, it looks somewhat like figure 2.</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-02.jpg" 
width=518> <BR><B>Figure 2: Random Pixels Demo</B></P>
<P>Once you can plot a pixel, you can do just about anything, including drawing 
lines, circles, rectangular frames, and so on. Doing all of that stuff is 
naturally beyond the scope of this article. I get you as far as plotting 
pixels.</P>
<H2>Blitting</H2>
<P>The primary use of SDL_Surfaces is not to fill rectangles nor to plot pixels. 
The main task is to copy rectangular sections from one surface to another, much 
like GDI's BitBlt function and DirectDraw's Blt or BltFast function. The 
function for doing that is SDL_BlitSurface.</P>
<BLOCKQUOTE><PRE class=code>int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
</PRE></BLOCKQUOTE>
<P>This function takes four parameters, the source surface, a source rectangle, 
a destination surface, and a destination rectangle. It returns 0 if everything 
is OK, and -1 if there was a problem. If the pointers to either rectangle are 
NULL, then the entire surface is assumed to be the source or destination area. 
Naturally, you need two surfaces in order to perform a blit, although you can 
use the same for both source and destination, at least in theory. The 
documentation warns that you should not call SDL_BlitSurface on a surface that 
is locked. So, time (already) for another quick example: the Amazing Bouncing 
Ball Demo of Death(tm)!</P>
<P>Start yourself a new project, name it SDLBouncingBall or something just as 
clever, and place the following code into main.cpp. Also, make a small bitmap 
that is 32x32 pixels in size, draw a circle in it, and save it as ball.bmp.</P>
<BLOCKQUOTE><PRE class=code>#include "SDL.h"

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 ) ;
<B>  //load bitmap
  SDL_Surface* pBitmap = SDL_LoadBMP ( "ball.bmp" ) ;

  //source and destination rectangles
  SDL_Rect rcSrc , rcDst ;
  rcSrc.w = pBitmap-&gt;w ;
  rcSrc.h = pBitmap-&gt;h ;
  rcSrc.x = 0 ;
  rcSrc.y = 0 ;
  rcDst = rcSrc ;

  //movement rate
  int dx = 2 , dy = 2 ;

</B>  //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>    //clear the screen
    SDL_FillRect ( pSurface , NULL , 0 ) ;

    //place the ball
    SDL_BlitSurface ( pBitmap , &amp;rcSrc , pSurface , &amp;rcDst ) ;

    //move the ball
    rcDst.x += dx ;
    rcDst.y += dy ;

    //check for bounces
    if ( rcDst.x == 0 || rcDst.x == SCREENWIDTH - rcDst.w ) dx = -dx ;
    if ( rcDst.y == 0 || rcDst.y == SCREENHEIGHT - rcDst.h ) dy = -dy ;

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

  //done
  return ( 0 ) ;
}
</PRE></BLOCKQUOTE>
<P>And if you run the application, you'll see whatever image you made for your 
ball bounce slowly around the window. Its not a particularly mind-boggling 
example, but it does adequately demonstrate SDL_BlitSurface. Plus it's 
hypnotic.... you are getting sleepy... sleeeeeepy....</P>
<P>Anyway. That's the simple blit demo. As we go along, this stuff just keeps 
getting easier. Figure 3 shows what this program looks like.</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-03.jpg" 
width=518> <BR><B>Figure 3: Bouncing Ball Demo</B></P>
<P>Just a quick note before we move on. When using the SDL_BlitSurface function, 
the contents of the SDL_Rect pointed to by dstrect can change if the destination 
rectangle is clipped, so often it is a good idea to make a copy of the 
destination rectangle prior to blitting, unless you absolutely know that the 
destination rectangle lies entirely withing the destination surface.</P>
<H2>Color Keys</H2>
<P>And now we come to the issue of transparency. In GDI, in order to make 
transparency work, you either need to use bitmasks, or else use the 
TransparentBlt function, which doesn't work on all versions of Windows. In 
DirectDraw, you have to set up a DDCOLORKEY for a surface that uses one, and you 
have to pass particular flags when using the Blt or BltFast function.</P>
<P>In SDL, setting up a transparent color is really easy. Unlike DirectDraw, you 
can only have one (1) transparent color for an SDL surface (of course, it's not 
like DirectDraw had widespread support for transparent color spaces, but I 
digress). In any case, a single color is usually enough for transparency anyway. 
Once a color key has been set for a surface, it is used whenever that surface is 
the source surface in a blit operation (which is nice, because then you don't 
have to remember which surfaces have color keys).</P>
<P>The function for setting the color key of a surface is called 
SDL_SetColorKey.</P>
<BLOCKQUOTE><PRE class=code>int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
</PRE></BLOCKQUOTE>
<P>This function takes three parameters: a pointer to a surface, a flag, and a 
key (the color, in the surfaces native pixel format). It returns an int, 0 if 
successful, and -1 if there is an error.</P>
<P>If flag contiains SDL_SRCCOLORKEY, then the value in key becomes the new 
transparent color key. If flag contains 0, any color key is cleared. You can 
retrieve the color key from the surface's pixel format, e.g. 
pSurface-&gt;format-&gt;colorkey.</P>
<P>Remember that key is in the native pixel format of the surface, and so if 
working with SDL_Color variables, you'll need to convert it with SDL_MapRGB.</P>
<P>No example for color keys, as their use is fairly obvious.</P>
<H2>Clipping Rectangles</H2>
<P>As a final topic, I'm going to show you how to set up a clipping rectangle 
for a surface. A clipping rectangle is the equivalent of an HRGN selected into 
an HDC in GDI, or an IDirectDrawClipper object attached to an IDirectDrawSurface 
object with SetClipper. Compared to their GDI or DirectDraw counterparts, the 
SDL clipping rectangle is not nearly as powerful or flexible. You can only have 
a single clipping rectangle at a time. For most purposes, that's enough. For 
times when it is not, you'll just have to get creative.</P>
<P>A clipping rectangle is just that: a rectangular area ( as described by an 
SDL_Rect variable) to which all destination blits are confined. Pixel plotting 
is unaffected by the clipping rectangle, as it directly accesses the pixel data 
of the surface. To set up a clipping rectangle for a surface, the function is 
SDL_SetClipRect.</P>
<BLOCKQUOTE><PRE class=code>void SDL_SetClipRect(SDL_Surface *surface, SDL_Rect *rect);
</PRE></BLOCKQUOTE>
<P>This function returns no value. It takes two parameters, a pointer to a 
surface (for which you are setting the clipping rectangle), and a pointer to an 
SDL_Rect structure (which contains the new clipping rectangle). If you pass NULL 
for rect, you will set the clipping area to the size of the entire surface.</P>
<P>To examine the contents of the clipping rectangle, you can either look at the 
clip_rect member of the SDL_Surface structure, or you can use SDL_GetClipRect, 
which has the same parameter list as SDL_SetClipRect, except that the current 
clipping rectangle is instead read into the variable pointed to by rect.</P>
<P>No example for clipping rectangles, as their use is fairly obvious.</P>
<H1>Summary</H1>
<P>We haven't totally exhausted the video system of SDL yet. There is still 
quite a bit more, but you've now been exposed to the basics. The functions shown 
in this article will be the ones most oft-used, although there are certainly 
some interesting aspects of some of the other functions, and later in the 
series, we shall return once again to the video subsystem. For now, this shall 
suffice.</P>
<P>Next Time: Events</P>
<P>Ernest S. Pazera</P>
<P><A href="mailto:ernestpazera@hotmail.com">ernestpazera@hotmail.com</A></P>
<P>Sources: SDL Documentation</P>
<P align=center><B><A 
href="http://www.gamedev.net/community/forums/topic.asp?key=featart&amp;uid=1603&amp;forum_id=35&amp;Topic_Title=The+Simple+DirectMedia+Layer+from+a+WIN32+Perspective%2C+Part+2%3A+SDL+Video">Discuss 
this article in the forums</A></B></P>
<P><BR><SPAN class=maintext-2>Date this article was posted to GameDev.net: 
<B>12/17/2001</B> <BR>(Note that this date does not necessarily correspond to 
the date the article was written)</SPAN> 
<P align=center>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品欧美精品| 午夜欧美电影在线观看| 亚洲欧美韩国综合色| 亚洲第一福利一区| 国产一区二区三区久久悠悠色av| 成人综合在线视频| 欧美精品亚洲二区| 国产精品久久福利| 玉足女爽爽91| 国产剧情一区二区三区| 欧美体内she精视频| 久久久影视传媒| 午夜亚洲国产au精品一区二区 | 热久久国产精品| 大胆亚洲人体视频| 91麻豆精品国产91久久久资源速度| 国产欧美1区2区3区| 亚洲午夜精品在线| 国产成人在线电影| 欧美一区二区大片| 亚洲精品高清视频在线观看| 国产乱码精品一区二区三区忘忧草 | 国产精品无码永久免费888| 美女视频黄免费的久久 | 中文字幕国产一区二区| 国产精品1024| 国产免费观看久久| 成人丝袜18视频在线观看| 精品乱人伦一区二区三区| 另类小说综合欧美亚洲| 日韩精品一区二区三区视频在线观看| 日韩一区精品视频| 欧美一区二区三区四区在线观看| 亚洲成人中文在线| 91精品国产色综合久久| 美女脱光内衣内裤视频久久影院| 日韩一区二区三| 狠狠色丁香久久婷婷综合丁香| 日韩欧美国产综合| 国产一区二区看久久| 国产精品青草综合久久久久99| caoporn国产精品| 一级做a爱片久久| 欧美精品丝袜中出| 蜜桃视频第一区免费观看| 久久亚洲一区二区三区四区| 福利91精品一区二区三区| 国产精品成人一区二区艾草 | 中文字幕日本乱码精品影院| 91女神在线视频| 日欧美一区二区| 久久久蜜桃精品| 99国产精品一区| 日韩中文字幕1| 国产亚洲欧洲997久久综合| av电影天堂一区二区在线| 亚洲电影欧美电影有声小说| 精品久久久久久久久久久久包黑料| 国产乱码精品一区二区三区av| 中文字幕色av一区二区三区| 91精品国产色综合久久不卡蜜臀 | 欧美美女一区二区在线观看| 国产一区二区三区黄视频 | www..com久久爱| 亚洲福利一区二区| 久久久久久97三级| 欧美日韩国产三级| 成人综合日日夜夜| 免费在线看一区| 亚洲三级视频在线观看| 精品国产乱码久久久久久图片| av日韩在线网站| 麻豆国产精品官网| 亚洲国产精品视频| 中文子幕无线码一区tr| 日韩欧美在线综合网| 91婷婷韩国欧美一区二区| 韩国女主播成人在线观看| 亚洲少妇最新在线视频| 精品国产乱码久久久久久牛牛| 日本福利一区二区| 国产iv一区二区三区| 美洲天堂一区二卡三卡四卡视频| 亚洲另类春色校园小说| 国产欧美日韩亚州综合 | 久久精品国产99久久6| 亚洲欧美二区三区| 久久久综合激的五月天| 欧美一级国产精品| 欧美日韩小视频| 91丝袜美腿高跟国产极品老师 | 丰满放荡岳乱妇91ww| 久久精品国产秦先生| 亚洲国产中文字幕在线视频综合| 精品国产亚洲一区二区三区在线观看| 91精品福利在线| 99久久99久久精品免费观看| 国产成人8x视频一区二区| 麻豆91免费看| 久久99精品国产91久久来源| 青青草原综合久久大伊人精品优势| 一区二区三区在线影院| 亚洲日本在线看| 亚洲视频 欧洲视频| 亚洲欧美在线观看| 日韩一区日韩二区| 国产精品高潮呻吟| 中文字幕一区二区不卡| 亚洲欧美中日韩| 国产精品久久久久久一区二区三区| 久久色成人在线| 国产欧美1区2区3区| 国产网红主播福利一区二区| 国产色产综合产在线视频| 国产亚洲精品7777| 国产日产欧产精品推荐色| 国产日产亚洲精品系列| 中文字幕日韩欧美一区二区三区| 中文字幕中文字幕一区| 亚洲精品高清视频在线观看| 亚洲福利一二三区| 日韩av在线播放中文字幕| 久久99精品久久久久久久久久久久| 老色鬼精品视频在线观看播放| 激情综合五月婷婷| 国产成人精品三级| 色婷婷av久久久久久久| 欧美乱妇20p| 国产亚洲精品aa午夜观看| 亚洲色图.com| 肉肉av福利一精品导航| 九九九精品视频| 成人免费视频一区| 在线观看亚洲精品视频| 884aa四虎影成人精品一区| 精品国产sm最大网站免费看| 亚洲国产精品99久久久久久久久| 综合激情成人伊人| 天堂久久久久va久久久久| 国产在线国偷精品免费看| 97久久久精品综合88久久| 欧美日韩高清一区| 日本一区二区三区视频视频| 亚洲一线二线三线久久久| 狠狠色狠狠色合久久伊人| 一本大道久久a久久精二百| 91麻豆精品国产自产在线观看一区| 久久精品视频一区二区三区| 一区二区三区在线免费视频| 久久99九九99精品| 色诱视频网站一区| 久久久久免费观看| 婷婷久久综合九色国产成人| 国产老妇另类xxxxx| 欧美日韩国产一级片| 国产精品免费丝袜| 免费成人av资源网| 91在线一区二区三区| 久久综合九色综合97_久久久| 亚洲午夜视频在线| 成人av影院在线| 精品国产青草久久久久福利| 亚洲国产一区二区视频| 高清免费成人av| 精品久久久久久久一区二区蜜臀| 免费视频最近日韩| 成人91在线观看| 精品国产1区二区| 日韩一区精品字幕| 欧美午夜在线观看| 中文字幕一区二区三区在线观看 | 日韩电影免费一区| 99久久国产综合精品色伊| 久久先锋影音av| 秋霞电影一区二区| 欧美乱妇一区二区三区不卡视频| 亚洲少妇30p| 成人一区在线观看| 久久一日本道色综合| 麻豆精品一区二区综合av| 欧美日本在线一区| 亚洲1区2区3区视频| 在线观看亚洲精品视频| 亚洲男帅同性gay1069| 成人动漫一区二区在线| 中文字幕欧美区| 国产福利一区二区| 久久久久久久综合日本| 国产一区欧美日韩| 久久午夜国产精品| 国产一区二区三区av电影| 2019国产精品| 国产精品99久久久久久久女警 | 日韩av中文在线观看| 欧美日韩午夜精品| 午夜电影久久久| 欧美一区二区精品在线| 秋霞午夜av一区二区三区| 欧美videos中文字幕| 精品一区二区影视|