LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 894|回复: 2

请教:OPENGL+SDL简单程序运行问题

[复制链接]
发表于 2006-10-5 23:50:23 | 显示全部楼层 |阅读模式
下面是一个简单的modes.cpp和Makefile,运行时候错误信息如下
./testMode
======================================================
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  1 (X_CreateWindow)
  Serial number of failed request:  156
  Current serial number in output stream:  158
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  2 (X_ChangeWindowAttributes)
  Resource id in failed request:  0x2c00012
  Serial number of failed request:  157
  Current serial number in output stream:  160

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2006-10-5 23:51:13 | 显示全部楼层
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "SDL.h"

//----------------------------------------------------------

// This list describes a large number of differrent pixel
// formats. Feel free to add or delete from the list.

typedef struct
{
  int bitsPerPixel;
  int bytesPerPixel;
  int red;
  int green;
  int blue;
  int alpha;
} pixelFormat;

pixelFormat formats[] =
  {
    { 1, 1, 1, 1, 1, 1},
    { 8, 1, 0, 0, 0, 0},
    { 8, 1, 3, 3, 2, 0},
    {12, 2, 4, 4, 4, 0},
    {15, 2, 5, 5, 5, 0},
    {16, 2, 4, 4, 4, 4},
    {16, 2, 5, 5, 5, 1},
    {16, 2, 5, 6, 5, 0},
    {24, 3, 8, 8, 8, 0},
    {24, 4, 8, 8, 8, 0},
    {32, 4, 8, 8, 8, 0},
    {32, 4, 8, 8, 8, 8},
  };

int numFormats = sizeof(formats) / sizeof(pixelFormat);

// zDepths is a list of the number of bits of Z buffer you
// want. Most of the values in the list a what you expect
// for real Z buffers, but 1, and 8 are there just for
// testing.

int zDepths[] = {0, 1, 8, 16, 24};
int numDepths = sizeof(zDepths) / sizeof(int);

int mssSize[] = {0, 2, 4, 8, 16};
int numMssSize = sizeof(mssSize) / sizeof(int);


//----------------------------------------------------------

// This function tries to set a specific OpenGL video mode
// based on its input parameters. It always prints
// information about the requested mode. If it can set the
// requested mode it prints the actual values for all the
// parameters that were set by the driver.

void testDisplayMode(int bitsPerPixel,
                     int red,
                     int green,
                     int blue,
                     int alpha,
                     int zBufDepth,
                     int doubleBuffer,
                     int fullScreen,
                     int msBuffers,
                     int msSamples)
{
  SDL_Surface *screen = NULL;
  Uint32 videoFlags = SDL_OPENGL;

  // Initialize SDL

  if (-1 == SDL_Init(SDL_INIT_EVERYTHING))
  {
    printf("Failed to initialize SDL error=%s\n", SDL_GetError());
    exit(1);
  }
  atexit(SDL_Quit);

  // Set all the OpenGL attributes.

  SDL_GL_SetAttribute(SDL_GL_RED_SIZE,   red);
  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, green);
  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,  blue);
  SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, alpha);
  SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, bitsPerPixel);
  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, zBufDepth);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, doubleBuffer);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msBuffers);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msSamples);

  // If it is a full screen mode then set the video flag
  // to request it.

  if (1 == fullScreen)
  {
    videoFlags |= SDL_FULLSCREEN;
  }

  // Set the video mode

  screen  = SDL_SetVideoMode(640, 480, 0, videoFlags);
  if (NULL == screen)
  {
    printf("could not set mode -- rgba= (%2d, %2d, %2d, %2d) z=%2d db= %d fs= %d bpp=%2d msb=%2d mss=%2d\n",
           red, green, blue, alpha,
           zBufDepth,
           doubleBuffer, fullScreen,
           bitsPerPixel,
           msBuffers, msSamples);
  }
  else
  {
    // Print information about the requested video mode.

    printf("\n -- set mode\n");
    printf("asked for rgba= (%2d, %2d, %2d, %2d) z=%2d db= %d fs= %d bpp=%2d msb=%2d mss=%2d\n",
           red, green, blue, alpha,
           zBufDepth,
           doubleBuffer, fullScreen,
           bitsPerPixel,
           msBuffers, msSamples);

    // Get the real values of the attributes. They are
    // rarely the same as what you asked for.

    SDL_GL_GetAttribute(SDL_GL_RED_SIZE,           &red);
    SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE,         &green);
    SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE,          &blue);
    SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE,         &alpha);
    SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE,        &bitsPerPixel);
    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE,         &zBufDepth);
    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER,       &doubleBuffer);
    SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msBuffers);
    SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msSamples);

    printf("but got   rgba= (%2d, %2d, %2d, %2d) z=%2d db= %d fs= %d bpp=%2d msb=%2d mss=%2d\n",
           red, green, blue, alpha,
           zBufDepth,
           doubleBuffer, fullScreen,
           bitsPerPixel,
           msBuffers, msSamples);
  }

  // Shut down SDL

  SDL_Quit();
}

//----------------------------------------------------------

// This is test driver. It iterates through all the pixel
// formats and all the Z buffer depths. It tries each
// combination of pixel format, Z buffer, single/double
// buffered, and windowed/full screen. That can be quite a
// few different modes. Be prepared for you computer
// screen to go blank for a while.

void enumerateDisplayModes()
{
  int pixelFormat = 0;
  int zBufFormat = 0;
  int fullScreen = 0;
  int msBuffers = 0;
  int msSamples = 0;
  int doubleBuffer = 0;

  for (fullScreen = 0; fullScreen <= 1; fullScreen++)
  {
    for (msBuffers = 0; msBuffers <= 1; msBuffers++)
    {
      for (doubleBuffer = 0; doubleBuffer <= 1; doubleBuffer++)
      {
        for (zBufFormat = 0; zBufFormat < numDepths; zBufFormat++)
        {
          for (pixelFormat = 0; pixelFormat < numFormats; pixelFormat++)
          {
            int bitsPerPixel = formats[pixelFormat].bitsPerPixel;
            int red = formats[pixelFormat].red;
            int green = formats[pixelFormat].green;
            int blue = formats[pixelFormat].blue;
            int alpha = formats[pixelFormat].alpha;
            int zBufDepth = zDepths[zBufFormat];

            if (0 == msBuffers)
            {
              testDisplayMode(bitsPerPixel,
                              red,
                              green,
                              blue,
                              alpha,
                              zBufDepth,
                              doubleBuffer,
                              fullScreen,
                              0,
                              0);
            }
            else
            {
              for (msSamples = 0; msSamples < numMssSize; msSamples++)
              {
                int sampleSize = mssSize[msSamples];
              
                testDisplayMode(bitsPerPixel,
                                red,
                                green,
                                blue,
                                alpha,
                                zBufDepth,
                                doubleBuffer,
                                fullScreen,
                                msBuffers,
                                sampleSize);
              }
            }
          }
        }
      }
    }
  }
}

//----------------------------------------------------------

int main(int argc, char **argv)
{
printf("======================================================\n");
enumerateDisplayModes();
printf("======================================================\n");
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-6 15:36:54 | 显示全部楼层
顶顶看看有没有人知道
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表