程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 【SDL的編程】VC環境搭建

【SDL的編程】VC環境搭建

編輯:關於C語言

SDLsimple DirectMedia Layer)是一個可跨平台的開源庫,最近由於自己的興趣,就把它windosXP下的環境搭建了下。 PC:Mircrosoft Windows XP Service Pack3 Platform:Mircrosoft Visual C++ 6.0 SourceCode:SDL-devel-1.2.14-VC6.zip
步驟     1. 解壓SDL-devel-1.2.14-VC6.zip.將解壓後的lib文件夾裡把SDL.lib SDLmain.lib拷貝到VC6.0安裝目錄的lib文件夾下面。     2. 將SDL.dll拷貝到系統盤的WINDOWS/SYSTEM32目錄下如果你要將之後生成的SDL應用程序轉移到其他沒有配置SDL環境的機器上用的話,請將SDL.dll一起拷貝)。     3. 在VC6.0安裝目錄的include文件夾下面新建一個SDL的目錄,並將SDL-devel-1.2.14-VC6.zip解壓後的include裡的文件拷貝到這個SDL目錄下面。     4. 打開VC6,新建一個project->win32 Application.打開project目錄下面的那個setting,選中C/C++,Category裡選中Code Generation,Use run-time library使用Multithread DLL.     5. 繼續在上面的setting中選中Link,Category裡選中input,在Object/library modules中填入SDL.lib SDLmain.lib     6. 在VC項目中新建一個cpp,並添加到項目中,編譯,運行.
相關鏈接
 
1.SDL http://www.libsdl.org/download-1.2.php
測試代碼 #include <stdlib.h>
#include "SDL/SDL.h"

SDL_Surface *screen;

void render()
{        
    // Lock surface if needed
    if (SDL_MUSTLOCK(screen))    
        if (SDL_LockSurface(screen) < 0)    
            return;

    // Ask SDL for the time in milliseconds
    int tick = SDL_GetTicks();

    // Declare a couple of variables
    int i, j, yofs, ofs;

    // Draw to screen
    yofs = 0;
    for (i = 0; i < 480; i++)
    {
        for (j = 0, ofs = yofs; j < 640; j++, ofs++)
        {
            ((unsigned int*)screen->pixels)[ofs] = i * i + j * j + tick;
        }
        yofs += screen->pitch / 4;
    }

    // Unlock if needed
    if (SDL_MUSTLOCK(screen))    
        SDL_UnlockSurface(screen);

    // Tell SDL to update the whole screen
    SDL_UpdateRect(screen, 0, 0, 640, 480);        
}


// Entry point
int main(int argc, char *argv[])
{
    // Initialize SDL's subsystems - in this case, only video.
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )    
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }

    // Register SDL_Quit to be called at exit; makes sure things are
    // cleaned up when we quit.
    atexit(SDL_Quit);
        
    // Attempt to create a 640x480 window with 32bit pixels.
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    
    // If we fail, return error.
    if ( screen == NULL )    
    {
        fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
        exit(1);
    }

    // Main loop: loop forever.
    while (1)
    {
        // Render stuff
        render();

        // Poll for events, and handle the ones we care about.
        SDL_Event event;
        while (SDL_PollEvent(&event))    
        {
            switch (event.type)    
            {
            case SDL_KEYDOWN:
                break;
            case SDL_KEYUP:
                // If escape is pressed, return (and thus, quit)
                if (event.key.keysym.sym == SDLK_ESCAPE)
                    return 0;
                break;
            case SDL_QUIT:
                return(0);
            }
        }
    }
    return 0;
}


 

本文出自 “Scalpel00” 博客,請務必保留此出處http://scalpel00.blog.51cto.com/1071749/247399

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved