亚洲欧美第一页_禁久久精品乱码_粉嫩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 頁
字號:
    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一区二区三区免费野_久草精品视频
aaa国产一区| 久久成人av少妇免费| 91亚洲精品一区二区乱码| 国产日韩亚洲欧美综合| 国产99久久久精品| 亚洲欧美色一区| 欧洲一区在线观看| 奇米一区二区三区av| 久久综合久色欧美综合狠狠| 国产乱码精品一区二区三| 国产精品网站导航| 色猫猫国产区一区二在线视频| 伊人性伊人情综合网| 欧美狂野另类xxxxoooo| 国内精品视频一区二区三区八戒| 国产欧美1区2区3区| 欧美亚洲禁片免费| 久久国产剧场电影| 亚洲视频图片小说| 91精品国产全国免费观看| 国产一区二区免费看| 国产精品久久一卡二卡| 欧美日韩不卡视频| 国产高清一区日本| 亚洲第一会所有码转帖| www亚洲一区| 色婷婷综合久久| 国内精品免费在线观看| 一区二区三区中文在线| 久久综合久久久久88| 欧美午夜电影一区| 韩国v欧美v亚洲v日本v| 亚洲精品视频自拍| 91精品国产综合久久精品| 国产高清视频一区| 亚洲电影一级黄| 欧美激情中文字幕| 欧美一区二区三区视频在线观看| 成人黄色大片在线观看| 毛片不卡一区二区| 一区二区三区国产| 国产亚洲精品aa午夜观看| 欧美日韩国产不卡| av一区二区久久| 久久91精品久久久久久秒播| 亚洲欧美国产毛片在线| 久久久久久久综合色一本| 欧美日韩一区二区三区四区五区| 国产成人免费9x9x人网站视频| 亚洲一区二区三区在线看| 国产日韩欧美精品一区| 日韩午夜在线播放| 欧美日韩日日夜夜| 91亚洲男人天堂| 成人禁用看黄a在线| 国产美女av一区二区三区| 午夜精品影院在线观看| 亚洲精品高清在线观看| 亚洲三级在线免费观看| 国产欧美日韩另类视频免费观看| 欧美一级夜夜爽| 欧美图片一区二区三区| 91麻豆精东视频| 不卡的看片网站| 国产伦精品一区二区三区视频青涩 | 亚洲免费在线观看视频| 久久久久久久免费视频了| 欧美一区二区三区播放老司机| 欧美在线视频日韩| 91蜜桃传媒精品久久久一区二区| 成人午夜av电影| 国产69精品久久久久777| 国产精品综合二区| 国产成人啪免费观看软件| 国产一区二区导航在线播放| 国产一区二区h| 丰满亚洲少妇av| 成人免费毛片片v| 高清不卡一二三区| 成人av午夜影院| 91丝袜美腿高跟国产极品老师 | 日韩精品自拍偷拍| 日韩一级免费观看| 欧美成人一区二区三区在线观看| 日韩一区二区三区视频在线观看 | 精品国一区二区三区| 精品三级在线观看| 国产拍欧美日韩视频二区| 国产欧美精品在线观看| 中文字幕va一区二区三区| 国产精品乱码一区二区三区软件| 国产精品久久影院| 亚洲一区二区三区视频在线播放 | 成人免费在线播放视频| 一区二区三区美女| 婷婷久久综合九色综合伊人色| 日韩精品五月天| 精品午夜久久福利影院| 懂色中文一区二区在线播放| 色婷婷av一区二区三区gif | 一区二区三区在线免费视频| 亚洲午夜久久久久| 蜜臀va亚洲va欧美va天堂| 国产精品一区在线观看你懂的| av在线这里只有精品| 欧美日韩一级片网站| 欧美成人bangbros| 亚洲欧洲日产国产综合网| 亚洲一区二区中文在线| 精品一二三四区| 91丨porny丨在线| 欧美一区二区网站| 国产精品久久久久aaaa| 亚洲成人综合网站| 国产精品123| 欧美乱熟臀69xxxxxx| 国产日韩欧美精品电影三级在线| 亚洲综合在线第一页| 国产自产2019最新不卡| 色婷婷国产精品久久包臀 | 成人国产精品免费观看视频| 欧美三片在线视频观看| 国产日韩精品一区二区三区| 亚洲国产精品久久久久秋霞影院| 狠狠色丁香九九婷婷综合五月| 91网址在线看| 久久久久久久久久电影| 亚洲成人高清在线| 成人三级伦理片| 欧美xxxxxxxx| 亚洲国产综合在线| av成人老司机| 国产亚洲精品免费| 麻豆国产91在线播放| 日本精品一级二级| 国产日韩高清在线| 狂野欧美性猛交blacked| 91久久人澡人人添人人爽欧美| 久久久久亚洲综合| 日韩av在线播放中文字幕| 91免费观看在线| 中文av一区特黄| 精品一区二区三区在线播放 | 国产91色综合久久免费分享| 欧美一级高清片| 亚洲第一av色| 91传媒视频在线播放| 国产精品进线69影院| 国产伦精品一区二区三区免费 | 欧美日韩国产在线播放网站| 中文字幕亚洲综合久久菠萝蜜| 国产精品一区二区你懂的| 欧美一区二区成人| 日韩专区一卡二卡| 欧美日韩在线电影| 亚洲一区视频在线观看视频| 色综合久久综合中文综合网| 久久精品夜色噜噜亚洲a∨| 精品一区二区久久久| 精品国产sm最大网站免费看| 美腿丝袜亚洲三区| 日韩西西人体444www| 秋霞电影网一区二区| 日韩一区二区三区免费观看| 天天亚洲美女在线视频| 欧美体内she精视频| 一区二区三区久久久| 日本二三区不卡| 亚洲综合色丁香婷婷六月图片| 91蝌蚪国产九色| 亚洲精品视频在线看| 色又黄又爽网站www久久| 亚洲黄网站在线观看| 欧美这里有精品| 日日夜夜精品视频天天综合网| 欧美一级在线免费| 国产一区二区三区视频在线播放| ww亚洲ww在线观看国产| 丁香另类激情小说| 一区精品在线播放| 欧美日韩一二三区| 日韩福利视频导航| 精品久久久久香蕉网| 国产电影精品久久禁18| 中文字幕亚洲电影| 欧美三级视频在线观看| 日韩高清不卡一区二区| 精品88久久久久88久久久| 丁香婷婷综合五月| 尤物av一区二区| 欧美一区二区三区思思人| 国产一区二区福利视频| 亚洲免费av高清| 在线播放91灌醉迷j高跟美女 | 中文字幕免费观看一区| 色综合久久中文综合久久牛| 五月天激情小说综合| 久久蜜桃av一区精品变态类天堂 | 欧美日本韩国一区| 国产真实乱对白精彩久久|