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

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

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

?? 游戲開發數據結構Data Structures for Game Programmers The Goodies Directory contains all sorts of stuff. For
?? 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一区二区三区免费野_久草精品视频
日韩综合在线视频| 一区二区高清视频在线观看| 欧美丰满一区二区免费视频| 欧美在线观看禁18| 欧美日韩大陆一区二区| 欧美一区二区三区系列电影| 欧美一区二区三区四区久久| 国产亚洲自拍一区| 国产精品国产三级国产aⅴ入口| 亚洲黄网站在线观看| 麻豆一区二区99久久久久| 国产成人精品1024| 5858s免费视频成人| 国产亚洲成aⅴ人片在线观看 | 国产成人亚洲综合色影视| 一本大道久久a久久综合| 26uuu另类欧美亚洲曰本| 久久久久久久久伊人| 亚洲另类在线视频| 丁香激情综合国产| 日韩一级完整毛片| 玉足女爽爽91| 欧美精品v日韩精品v韩国精品v| 久久久精品一品道一区| 国产精品久久看| 国产成人高清在线| 精品国产乱码久久久久久免费 | 91在线看国产| 国产精品第五页| 国产成人av电影在线| 国产农村妇女毛片精品久久麻豆| 日韩av电影免费观看高清完整版在线观看| av激情成人网| 亚洲国产精品人人做人人爽| 91麻豆国产福利精品| 1区2区3区精品视频| 99久久久久久99| 亚洲人成在线播放网站岛国| 9i在线看片成人免费| 国产精品欧美经典| 欧美少妇性性性| 日本美女一区二区三区视频| 精品日韩成人av| 成人免费va视频| 亚洲综合一区二区三区| 欧美一级高清大全免费观看| 婷婷成人综合网| 国产欧美日韩不卡免费| 欧美午夜视频网站| 久久99在线观看| 欧美国产精品一区| 色婷婷av一区二区三区gif| 亚洲午夜久久久| 精品国产三级电影在线观看| 国产精品性做久久久久久| 最新国产成人在线观看| 在线观看欧美黄色| 午夜精品久久久久久久久久| 欧美一级高清片在线观看| 国产精品456| 亚洲成精国产精品女| 欧美电视剧在线看免费| 国产精品18久久久久久久久久久久| 久久精品在这里| 欧美一区二区免费观在线| 99视频一区二区| 国产成人在线影院| 久久精品国产第一区二区三区| 一区二区三区欧美日韩| 国产精品人妖ts系列视频 | 日韩中文字幕麻豆| 一区二区在线观看av| 国产免费久久精品| 久久久精品黄色| 欧美成人aa大片| 精品999在线播放| 欧美刺激脚交jootjob| 日韩网站在线看片你懂的| 欧美片网站yy| 5858s免费视频成人| 欧美一区日本一区韩国一区| 在线播放中文一区| 日韩免费视频线观看| 久久亚洲精品小早川怜子| 久久综合色一综合色88| 国产喂奶挤奶一区二区三区| 国产亚洲午夜高清国产拍精品| 精品国精品国产尤物美女| 欧美日韩国产高清一区二区| 91美女福利视频| 欧美亚洲一区二区三区四区| 欧美手机在线视频| 欧美一区二区三区婷婷月色| 日韩欧美在线一区二区三区| 精品久久五月天| 成人免费一区二区三区视频| 亚洲欧美日韩国产综合在线| 日韩精品一二区| av在线播放一区二区三区| 欧美日韩一区二区在线观看视频 | 国产精品色噜噜| 午夜视频在线观看一区二区| 日本亚洲三级在线| 成人一道本在线| 91精品黄色片免费大全| 久久久精品人体av艺术| 午夜日韩在线观看| 9i看片成人免费高清| 日韩视频免费观看高清完整版| 国产精品久久久久久亚洲毛片 | 欧美va在线播放| 自拍偷拍亚洲激情| 国产电影精品久久禁18| 色天使久久综合网天天| 欧美激情一区二区三区在线| 久草中文综合在线| 欧美成人福利视频| 久久超碰97人人做人人爱| 色系网站成人免费| 中文字幕在线播放不卡一区| 美国毛片一区二区三区| 欧美精品丝袜中出| 一区二区三区四区亚洲| 91色乱码一区二区三区| 国产亚洲一区二区三区四区| 国产激情一区二区三区四区| 精品成人佐山爱一区二区| 国产一区二区三区观看| 久久综合久久综合亚洲| 国产麻豆精品视频| 欧美国产日韩一二三区| 粉嫩av亚洲一区二区图片| 日韩欧美精品在线视频| 国产乱对白刺激视频不卡| 国产视频一区不卡| 色偷偷一区二区三区| 亚洲国产一区视频| 欧美精品一区在线观看| 国产一区二区三区黄视频| 亚洲欧洲一区二区在线播放| 99精品一区二区| 午夜激情一区二区| 国产清纯在线一区二区www| 91浏览器打开| 国内精品写真在线观看| 亚洲精品福利视频网站| 精品国产电影一区二区| 色老汉一区二区三区| 美日韩黄色大片| 亚洲精品欧美二区三区中文字幕| 欧美久久久久久久久中文字幕| 久久精品国产久精国产爱| 亚洲美女精品一区| 日本一区二区久久| 日韩精品一区二区三区四区视频| 91尤物视频在线观看| 懂色中文一区二区在线播放| 日韩成人dvd| 丝袜诱惑亚洲看片| 亚洲久本草在线中文字幕| 中文字幕欧美一| 中文字幕精品—区二区四季| 日韩欧美国产电影| 69成人精品免费视频| 精品国产a毛片| 欧美精品一区二区蜜臀亚洲| 在线播放中文一区| 精品视频在线看| 欧美日韩综合色| 欧美亚洲免费在线一区| 91丨九色丨黑人外教| 91在线码无精品| 成人av手机在线观看| www.日本不卡| 国产一区二区网址| 成人综合婷婷国产精品久久免费| 蜜桃av一区二区| 成人午夜激情在线| 在线亚洲高清视频| 欧美一区2区视频在线观看| 日韩一区二区中文字幕| 欧美一区二区三区在线| 日韩亚洲欧美高清| 久久久噜噜噜久久人人看| 国产欧美一区二区三区网站| 久久久www成人免费毛片麻豆| 国产色一区二区| 亚洲二区视频在线| 午夜欧美2019年伦理| 蜜桃久久av一区| 国产a久久麻豆| 在线观看不卡一区| 欧美成人综合网站| 日韩美女久久久| 日韩精品视频网| 国产成人精品亚洲777人妖| 在线观看视频一区| 国产日韩av一区二区| 亚洲一区二区三区影院| 黄网站免费久久|