当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_DestroyWindow函数代码示例

本文整理汇总了C++中SDL_DestroyWindow函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_DestroyWindow函数的具体用法?C++ SDL_DestroyWindow怎么用?C++ SDL_DestroyWindow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_DestroyWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WatchGameController

SDL_bool
WatchGameController(SDL_GameController * gamecontroller)
{
    /* This is indexed by SDL_GameControllerButton. */
    static const struct { int x; int y; } button_positions[] = {
        {387, 167},  /* A */
        {431, 132},  /* B */
        {342, 132},  /* X */
        {389, 101},  /* Y */
        {174, 132},  /* BACK */
        {233, 132},  /* GUIDE */
        {289, 132},  /* START */
        {75,  154},  /* LEFTSTICK */
        {305, 230},  /* RIGHTSTICK */
        {77,  40},   /* LEFTSHOULDER */
        {396, 36},   /* RIGHTSHOULDER */
        {154, 188},  /* DPAD_UP */
        {154, 249},  /* DPAD_DOWN */
        {116, 217},  /* DPAD_LEFT */
        {186, 217},  /* DPAD_RIGHT */
    };

    /* This is indexed by SDL_GameControllerAxis. */
    static const struct { int x; int y; double angle; } axis_positions[] = {
        {75,  154, 0.0},  /* LEFTX */
        {75,  154, 90.0},  /* LEFTY */
        {305, 230, 0.0},  /* RIGHTX */
        {305, 230, 90.0},  /* RIGHTY */
        {91, 0, 90.0},     /* TRIGGERLEFT */
        {375, 0, 90.0},    /* TRIGGERRIGHT */
    };

    const char *name = SDL_GameControllerName(gamecontroller);
    const char *basetitle = "Game Controller Test: ";
    const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
    char *title = (char *)SDL_malloc(titlelen);
    SDL_Texture *background, *button, *axis;
    SDL_Window *window = NULL;
    SDL_Renderer *screen = NULL;
    SDL_bool retval = SDL_FALSE;
    SDL_bool done = SDL_FALSE;
    SDL_Event event;
    int i;

    if (title) {
        SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
    }

    /* Create a window to display controller state */
    window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, 0);
    if (window == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
        return SDL_FALSE;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }

    SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(screen);
    SDL_RenderPresent(screen);
    SDL_RaiseWindow(window);

    /* scale for platforms that don't give you the window size you asked for. */
    SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

    background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
    button = LoadTexture(screen, "button.bmp", SDL_TRUE);
    axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);

    if (!background || !button || !axis) {
        SDL_DestroyRenderer(screen);
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }
    SDL_SetTextureColorMod(button, 10, 255, 21);
    SDL_SetTextureColorMod(axis, 10, 255, 21);

    /* !!! FIXME: */
    /*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/

    /* Print info about the controller we are watching */
    SDL_Log("Watching controller %s\n",  name ? name : "Unknown Controller");

    /* Loop, getting controller events! */
    while (!done) {
        /* blank screen, set up for drawing this frame. */
        SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
        SDL_RenderClear(screen);
        SDL_RenderCopy(screen, background, NULL, NULL);

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
//.........这里部分代码省略.........
开发者ID:AaronPerl,项目名称:OpenHand,代码行数:101,代码来源:testgamecontroller.c

示例2: GLimp_SetMode


//.........这里部分代码省略.........
		{
			glConfig.vidWidth  = 640;
			glConfig.vidHeight = 480;
			Ren_Print("Cannot determine display resolution, assuming 640x480\n");
		}

		glConfig.windowAspect = (float)glConfig.vidWidth / (float)glConfig.vidHeight;
	}
	else if (!R_GetModeInfo(&glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode))
	{
		Ren_Print("invalid mode\n");
		return RSERR_INVALID_MODE;
	}
	Ren_Print("%dx%d\n", glConfig.vidWidth, glConfig.vidHeight);

	// Center window
	if (r_centerWindow->integer && !fullscreen)
	{
		x = (desktopMode.w / 2) - (glConfig.vidWidth / 2);
		y = (desktopMode.h / 2) - (glConfig.vidHeight / 2);
	}

	// Destroy existing state if it exists
	if (SDL_glContext != NULL)
	{
		SDL_GL_DeleteContext(SDL_glContext);
		SDL_glContext = NULL;
	}

	if (main_window != NULL)
	{
		SDL_GetWindowPosition(main_window, &x, &y);
		Ren_Developer("Existing window at %dx%d before being destroyed\n", x, y);
		SDL_DestroyWindow(main_window);
		main_window = NULL;
	}

	if (fullscreen)
	{
		if (r_mode->integer == -2)
		{
			flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
		}
		else
		{
			flags |= SDL_WINDOW_FULLSCREEN;
		}

		glConfig.isFullscreen = qtrue;
	}
	else
	{
		if (noborder)
		{
			flags |= SDL_WINDOW_BORDERLESS;
		}

		glConfig.isFullscreen = qfalse;
	}

	colorBits = r_colorbits->value;
	if ((!colorBits) || (colorBits >= 32))
	{
		colorBits = 24;
	}
开发者ID:gitter-badger,项目名称:etlegacy,代码行数:66,代码来源:sdl_glimp.c

示例3: main

int main(int argc, char** argv)
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow("SDL Practice4",
                                          SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,
                                          800,700,
                                          SDL_WINDOW_SHOWN);
    SDL_Renderer* rend = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);  //创建renderer
    SDL_RenderClear(rend);  //清空rend

    SDL_Surface* image_surface = SDL_LoadBMP("x.bmp");
    SDL_Texture* image_texture = SDL_CreateTextureFromSurface(rend, image_surface); //将surface转换为texture并显示在rend上

    SDL_Event event;
    SDL_Rect pos;
    pos.x=0;
    pos.y=0;
    pos.w=image_surface->w;
    pos.h=image_surface->h;

    SDL_Rect image_pos;
    image_pos.x = 0;
    image_pos.y = 0;
    image_pos.w = image_surface->w;
    image_pos.h = image_surface->h;
    bool quit=false;
    bool pressed = false;
    while(!quit)
    {
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
                quit = true;
            if(event.type == SDL_MOUSEBUTTONDOWN)
            {
                if(event.button.button == SDL_BUTTON_LEFT)
                {
                    image_pos.x = event.motion.x - pos.x;
                    image_pos.y = event.motion.y - pos.y;
                    if(image_pos.x>=0 && image_pos.x<=image_pos.w && image_pos.y>0 && image_pos.y<image_pos.h)
                        pressed = true;
                }
            }
            if(pressed && event.type == SDL_MOUSEMOTION)
            {
                pos.x = event.motion.x - image_pos.x;
                pos.y = event.motion.y - image_pos.y;
            }
            if(event.type == SDL_MOUSEBUTTONUP)
            {
                if(pressed && event.button.button == SDL_BUTTON_LEFT)
                {
                    pressed = false;
                }
            }
        }
        SDL_RenderClear(rend);  //清空rend
        SDL_RenderCopy(rend, image_texture, NULL, &pos);    //将texture显示到rend上
        SDL_Delay(5);
        SDL_RenderPresent(rend);    //显示rend
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}
开发者ID:Zix777,项目名称:C,代码行数:66,代码来源:main.c

示例4: get_flags

int CVideo::setMode(int w, int h, int bits_per_pixel, int flags)
{
	bool reset_zoom = frameBuffer? false: true;

	mode_changed_ = true;

	flags = get_flags(flags);

	if (current_format == SDL_PIXELFORMAT_UNKNOWN) {
		current_format = SDL_PIXELFORMAT_ARGB8888;
	}

	fullScreen = (flags & SDL_WINDOW_FULLSCREEN) != 0;
	if (window) {
		SDL_DestroyWindow(window);
	}
	if (frameTexture) {
		SDL_DestroyTexture(frameTexture);
	}
	if (renderer) {
		SDL_DestroyRenderer(renderer);
	}

	int x = SDL_WINDOWPOS_UNDEFINED;
	int y = SDL_WINDOWPOS_UNDEFINED;
#if (defined(__APPLE__) && TARGET_OS_IPHONE)
	if (gui2::twidget::hdpi) {
		x = y = 0;
	}
#endif
	window = SDL_CreateWindow(_(game_config::app_msgid.c_str()), x, y, w, h, flags);

	int ret_w, ret_h;
	SDL_GetWindowSize(window, &ret_w, &ret_h);

	renderer = SDL_CreateRenderer(window, -1, 0);

#if (defined(__APPLE__) && TARGET_OS_IPHONE)
	if (gui2::twidget::hdpi) {
		// Fix Bug!
		SDL_SetWindowSize(window, w, h);
	}
#endif

	frameBuffer = SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
	SDL_SetSurfaceBlendMode(frameBuffer, SDL_BLENDMODE_NONE);
	frameTexture = SDL_CreateTexture(renderer, current_format, SDL_TEXTUREACCESS_STREAMING, w, h);

	// frameBuffer's refcount should be 1. If not, check SDL_SetVideoMode!
	// 1 is holded by frameBuffer.
	if (frameBuffer.get()->refcount != 1) {
		return 0;
	}
	
	if (frameBuffer != NULL) {
		image::set_pixel_format(frameBuffer->format);
		game_config::tiny_gui = frameBuffer->w < 800 * gui2::twidget::hdpi_ratio || frameBuffer->h < 600 * gui2::twidget::hdpi_ratio;
		if (reset_zoom) {
			int zoom = preferences::zoom();
			display::initial_zoom = zoom;
			image::set_zoom(display::initial_zoom);
		}
		return bits_per_pixel;
	} else	{
		return 0;
	}
}
开发者ID:freeors,项目名称:War-Of-Kingdom,代码行数:67,代码来源:video.cpp

示例5: main

int main(){


    TempSettings gamesettings;

    gamesettings.mapw = 10;
    gamesettings.maph = 6;
    gamesettings.mapx = 0;
    gamesettings.mapy = 0;
    gamesettings.mapmidx = gamesettings.mapw/2.0;
    gamesettings.mapmidy = gamesettings.maph/2.0;
    gamesettings.window_width = 1300;
    gamesettings.window_height = 800;

    // initialize window, renderer, textures
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
        std::cerr << "SDL_Init error: " << SDL_GetError() << std::endl;
        return 1;
    }

    if (TTF_Init() != 0){
        std::cerr << "TTF_Init error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    SDL_Window* window = SDL_CreateWindow("deathblade_floating", 0, 0, gamesettings.window_width, gamesettings.window_height, SDL_WINDOW_SHOWN);
    if (window == nullptr){
        std::cerr << "SDL_CreateWindow error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    if (renderer == nullptr){
        std::cerr << "SDL_CreateRenderer error: " << SDL_GetError() << std::endl;
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 1;
    }
    std::string resource_path = getResourcePath("");
    std::string charfile = resource_path + "initialcharacter.png";
    std::string bgfile = resource_path + "initialbackgroundtile.png";
    std::string starfile = resource_path + "star.png";
    std::string wallfile = resource_path + "wall.png";
    SDL_Texture* character_texture = IMG_LoadTexture(renderer, charfile.c_str());
    SDL_Texture* bgtile_texture = IMG_LoadTexture(renderer, bgfile.c_str());
    SDL_Texture* star_texture = IMG_LoadTexture(renderer, starfile.c_str());
    SDL_Texture* wall_texture = IMG_LoadTexture(renderer,wallfile.c_str());
    if (character_texture == nullptr || bgtile_texture == nullptr || star_texture == nullptr || wall_texture == nullptr){
            std::cerr << "IMG_LoadTexture error: " << SDL_GetError() << std::endl;
            SDL_DestroyTexture(character_texture);
            SDL_DestroyTexture(bgtile_texture);
            SDL_DestroyRenderer(renderer);
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
    }

    std::string fontfile = resource_path + "sample.ttf";
    TTF_Font* font = TTF_OpenFont(fontfile.c_str(), 15);
    if (font == NULL){
        std::cerr << "TTF_OpenFont error: " << SDL_GetError() << std::endl;
    }


	CameraControl camera(&gamesettings);
    ObjectController objects;
    DeveloperConsoleClass console(&gamesettings);
    console.add_controller(&console);
    console.add_controller(&camera);

    const double tilew = 0.5;
    const double tileh = 0.5;
    double mousex = gamesettings.mapmidx;
    double mousey = gamesettings.mapmidy;
    int mousepx = gamesettings.window_width/2;
    int mousepy = gamesettings.window_height/2;

    double wallthickness = 0.1;
    TextureWall bottomwall, topwall, leftwall, rightwall;
    bottomwall.x = gamesettings.mapw/2;
    bottomwall.y = gamesettings.maph+wallthickness/2;
    bottomwall.setTexture(wall_texture,gamesettings.mapw,wallthickness);
    objects.add_object(&bottomwall);

    topwall.x = gamesettings.mapw/2;
    topwall.y = -wallthickness/2;
    topwall.setTexture(wall_texture,gamesettings.mapw,wallthickness);
    objects.add_object(&topwall);

    leftwall.x = -wallthickness/2;
    leftwall.y = gamesettings.maph/2;
    leftwall.setTexture(wall_texture,wallthickness,gamesettings.maph);
    objects.add_object(&leftwall);

    rightwall.x = gamesettings.mapw + wallthickness/2;
    rightwall.y = gamesettings.maph/2;
    rightwall.setTexture(wall_texture,wallthickness,gamesettings.maph);
    objects.add_object(&rightwall);
//.........这里部分代码省略.........
开发者ID:jamethy,项目名称:battle_room,代码行数:101,代码来源:main.cpp

示例6: SDL_DestroyRenderer

PixelDrawer::~PixelDrawer()
{
	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);
	SDL_Quit();
}
开发者ID:ruslashev,项目名称:vxr,代码行数:6,代码来源:pixeldrawer.cpp

示例7: createLandmarks

std::vector<Landmark> createLandmarks()
{
    std::vector<Landmark> lmks;

    SDL_Color color_red = {.r = 255, .g = 0, .b = 0, .a = 255 };
    SDL_Color color_green = {.r = 0, .g = 255, .b = 0, .a = 255 };
    SDL_Color color_blue = {.r = 0, .g = 0, .b = 255, .a = 255 };
    SDL_Color color_purple = {.r = 255, .g = 0, .b = 255, .a = 255 };

    lmks.push_back( Landmark(300.,300.,color_red));
    lmks.push_back( Landmark(124.,478.,color_blue));
//    lmks.push_back( Landmark(214.,312.,color_purple));

    return lmks;
}


int main() {

    if (SDL_Init(SDL_INIT_VIDEO) != 0){
        std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
        return 1;
    }


    SDL_Window *win = SDL_CreateWindow("Robot Program", XSTART, YSTART, WWIDTH, WHEIGHT, SDL_WINDOW_SHOWN);
    if (win == nullptr){
        std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (ren == nullptr){
        SDL_DestroyWindow(win);
        std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }


    std::vector<Landmark> landmarks = createLandmarks();

    SDL_Color orange {.r=255, .g=165, .b=0, .a=255};
    SDL_Color red {.r=255, .g=0, .b=0, .a=255};
    SDL_Color gray {.r=128, .g=128, .b=128, .a=255};

    Robot robby(200, 200, 0.0, 20, red);

    // Kalman filter stuff
    int n = 3; // number of state variables (x,y,phi)
    int m = 3; // number of measurements (landmark x, y, index)

    // Best guess of initial states
    Eigen::VectorXf x0(n); //[x, y, phi]
    x0 << 200., 200., 0.0;
    Robot robby_estimate(x0(0), x0(1), x0(2), 18, gray);

    // control vector:
    Eigen::VectorXf control(2); //  [v, omega]


    Eigen::MatrixXf A(n, n); // System dynamics matrix
    Eigen::MatrixXf C(m, n); // Output matrix
    Eigen::MatrixXf Q(n, n); // Process noise covariance
    Eigen::MatrixXf R(m, m); // Measurement noise covariance
    Eigen::MatrixXf covariance(n, n); // Estimate error covariance


    // Reasonable covariance matrices
    covariance <<    5., .0, .0,
                     .0, 5., .0,
                    .0, .0,  5.;

    R <<    1.0, 0., 0.,
            0., 1.0, 0.,
            0., 0.,  0.1;

    Q <<    0.1, 0.1, 0.1,
            0.1, 0.1, 0.1,
            0.1, 0.1, 0.1;

    KalmanFilter kf(DT, A, C, Q, R, covariance);

    float t0 = 0.0;
    kf.init(t0, x0);

    // rendering loop
    int i = 0;
    while (i < 10000) {

        //First clear the renderer
        SDL_RenderClear(ren);

        //Draw the texture
        SDL_SetRenderDrawColor(ren, 200, 200, 255, 255);

        SDL_RenderClear(ren); // fill the scene with white

        SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
//.........这里部分代码省略.........
开发者ID:jzuern,项目名称:robot-localization,代码行数:101,代码来源:main.cpp

示例8: SDL_DestroyWindow

void cleanup<SDL_Window>(SDL_Window *win){
	if (!win){
		return;
	}
	SDL_DestroyWindow(win);
}
开发者ID:imousewyfzml,项目名称:mylibrary,代码行数:6,代码来源:cleanup.cpp

示例9: CommonEvent

void
CommonEvent(CommonState * state, SDL_Event * event, int *done)
{
    int i;

    if (state->verbose & VERBOSE_EVENT) {
        PrintEvent(event);
    }

    switch (event->type) {
    case SDL_WINDOWEVENT:
        switch (event->window.event) {
        case SDL_WINDOWEVENT_CLOSE:
			{
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
                if (window) {
					SDL_DestroyWindow(window);
				}
			}
            break;
        }
        break;
    case SDL_KEYDOWN:
        switch (event->key.keysym.sym) {
            /* Add hotkeys here */
        case SDLK_PRINTSCREEN: {
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    for (i = 0; i < state->num_windows; ++i) {
                        if (window == state->windows[i]) {
                            ScreenShot(state->renderers[i]);
                        }
                    }
                }
            }
            break;
        case SDLK_c:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-C copy awesome text! */
                SDL_SetClipboardText("SDL rocks!\nYou know it!");
                printf("Copied text to clipboard\n");
            }
            break;
        case SDLK_v:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-V paste awesome text! */
                char *text = SDL_GetClipboardText();
                if (*text) {
                    printf("Clipboard: %s\n", text);
                } else {
                    printf("Clipboard is empty\n");
                }
                SDL_free(text);
            }
            break;
        case SDLK_g:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-G toggle grab */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window));
                }
            }
            break;
        case SDLK_m:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-M maximize */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_MAXIMIZED) {
                        SDL_RestoreWindow(window);
                    } else {
                        SDL_MaximizeWindow(window);
                    }
                }
            }
            break;
        case SDLK_r:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-R toggle mouse relative mode */
                SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode());
            }
            break;
        case SDLK_z:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-Z minimize */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    SDL_MinimizeWindow(window);
                }
            }
            break;
        case SDLK_RETURN:
            if (event->key.keysym.mod & KMOD_CTRL) {
                /* Ctrl-Enter toggle fullscreen */
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
                if (window) {
                    Uint32 flags = SDL_GetWindowFlags(window);
                    if (flags & SDL_WINDOW_FULLSCREEN) {
//.........这里部分代码省略.........
开发者ID:aduros,项目名称:SDL,代码行数:101,代码来源:common.c

示例10: glDeleteVertexArrays

OpenGLRenderer::~OpenGLRenderer() {
    glDeleteVertexArrays(1, &vertex_array_id_);
    SDL_GL_DeleteContext(context_);
    SDL_DestroyWindow(window_);
}
开发者ID:bk5115545,项目名称:3d_app_framework,代码行数:5,代码来源:opengl_renderer.cpp

示例11: SDL_GL_DeleteContext

Renderer::~Renderer()
{
    SDL_GL_DeleteContext(glcontext);
    SDL_DestroyWindow(window);
    SDL_Quit();
}
开发者ID:kamx44,项目名称:MokaGame,代码行数:6,代码来源:Renderer.cpp

示例12: main


//.........这里部分代码省略.........
		iChannel3Index=std::atoi(c3Arg);
	}
	



	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window* window;
	SDL_GLContext maincontext;

	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,1);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	window = SDL_CreateWindow("Shadertoy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL  );

	maincontext = SDL_GL_CreateContext(window);

	glViewport(0,0,width,height);
	
	SDL_GL_SetSwapInterval(1);

	std::cout<<glGetString(GL_VERSION)<<"\n";
	
	std::ifstream shaderInStream(argv[1]);
	std::stringstream buffer;
	buffer << uniforms << shaderInStream.rdbuf()<<mainMethod;
	std::string contents = buffer.str();
	
	GLuint programIndex = compile(contents);
	glUseProgram(programIndex);

	iResolutionLocation = glGetUniformLocation(programIndex, "iResolution");
	iGlobalTimeLocation = glGetUniformLocation(programIndex, "iGlobalTime");
	iMouseLocation = glGetUniformLocation(programIndex, "iMouse");
	iChannel0Location = glGetUniformLocation(programIndex, "iChannel0");
	iChannel1Location = glGetUniformLocation(programIndex, "iChannel1");
	iChannel2Location = glGetUniformLocation(programIndex, "iChannel2");
	iChannel3Location = glGetUniformLocation(programIndex, "iChannel3");
	iChannelResolutionLocation = glGetUniformLocation(programIndex, "iChannelResolution");


	
	loadTextures();
	
	
	setStaticUniforms();
	
	
	unsigned int lastTime=SDL_GetTicks();
	unsigned int deltaCounter=0;
	unsigned int fps=0;
	unsigned int secondCounter=0;

	bool hasQuit=false;
	while(!hasQuit){
		unsigned int now=SDL_GetTicks();
		deltaCounter+=now-lastTime;
		secondCounter+=now-lastTime;
		lastTime=now;

		while(deltaCounter>17){
			deltaCounter-=17;
		}
		
		SDL_Event e;
		while(SDL_PollEvent(&e)){
			switch(e.type){
				case SDL_QUIT:
					hasQuit=true;
					break;
				case SDL_MOUSEBUTTONDOWN:
					mouseXPos=mouseXClick=e.button.x;
					mouseYPos=mouseYClick=e.button.y;
					break;
				case SDL_MOUSEMOTION:
					if(e.motion.state&SDL_BUTTON(1)){
						mouseXPos=e.motion.x;
						mouseYPos=e.motion.y;
					}
					
				

			}
		}
		setDynamicUniforms();
		glRects(-1,-1,1,1);
		SDL_GL_SwapWindow(window);
		fps++;
		if(secondCounter>1000){
			std::cout<<fps<<" FPS\n";
			fps=0;
			secondCounter-=1000;
		}
//		SDL_Delay(10);
	}


	SDL_DestroyWindow(window);
	SDL_Quit();
}
开发者ID:mad-s,项目名称:shadertoy,代码行数:101,代码来源:main.cpp

示例13: main

int main(int argc, char**argv)
{
    if(SDL_Init(SDL_INIT_VIDEO)==-1)
    {
        SDL_Log("%s\n", SDL_GetError());
    }
    SDL_Window* wnd;
    wnd = SDL_CreateWindow
          ("",
           SDL_WINDOWPOS_UNDEFINED,
           SDL_WINDOWPOS_UNDEFINED,
           1680, 1050,
           SDL_WINDOW_OPENGL);
    if(wnd == NULL)
    {
        SDL_Log("%s\n", SDL_GetError());
    }
    SDL_GLContext glctxt = SDL_GL_CreateContext(wnd);
    if(glctxt == NULL)
    {
        SDL_Log("%s\n", SDL_GetError());
    }
    const Uint8* kbd = SDL_GetKeyboardState(NULL);
    if(kbd == NULL)
    {
        SDL_Log("%s\n", SDL_GetError());
    }

    int done=0;
    float t=0.0;
    float dt=0.0;
    frame_init();
    int wnd_w, wnd_h;
    SDL_GetWindowSize(wnd, &wnd_w, &wnd_h);
    render_init(wnd_w, wnd_h);

    float mousex_old;
    float mousey_old;

    while(!done)
    {
        int start_time = SDL_GetTicks();
        /* react to system quit event */
        SDL_Event evt;
        while(SDL_PollEvent(&evt))
        {
            if(evt.type==SDL_QUIT)
            {
                done = 1;
            }
        }

        /* get mouse state */
        int imousex, imousey; /* i for int */
        Uint32 mouseb = SDL_GetMouseState(&imousex, &imousey);
        /* convert "integer" coordinates to "floating point" coordinates */
        /* (0.5, 0.5) is monitor center */
        /* (1.0, 1.0) is top right corner */
        /* (0.0, 0.0) is bottom left corner */
        float mousex, mousey;
        int wnd_w, wnd_h;
        SDL_GetWindowSize(wnd, &wnd_w, &wnd_h);
        mousex = (float)(imousex)/(wnd_w);
        mousey = 1.0f - (float)(imousey)/(wnd_h);

        float dx = mousex - mousex_old;
        float dy = mousey - mousey_old;

        mousex_old = mousex;
        mousey_old = mousey;

        done = frame(dt, evt, kbd, dx, dy, mouseb);
        render();
        SDL_GL_SwapWindow(wnd);
        /* sleep */
        int dt_int = SDL_GetTicks() - start_time;
        if(dt_int < DELAY_TIME)
            SDL_Delay(DELAY_TIME - dt_int);
        dt = (float)dt_int / 1.0e3;
    }
    frame_shutdown();
    render_shutdown();

    /* free resources */
    SDL_GL_DeleteContext(glctxt);
    SDL_DestroyWindow(wnd);
    SDL_Quit();

    return 0;
}
开发者ID:nchashch,项目名称:orbital-mechanics,代码行数:90,代码来源:main.cpp

示例14: main

int main(int argc, char* argv[])
{
	SDL_GLContext context;
	SDL_Window *window;

	SDL_Init(SDL_INIT_VIDEO);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

	window = SDL_CreateWindow(
		"Wolf",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		640,
		480,
		SDL_WINDOW_OPENGL
	);
	if (!window) {
		fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
		return 1;
	}

	context = SDL_GL_CreateContext(window);

	glewExperimental = GL_TRUE;
	glewInit();

	wolf_load_texture(0, "Assets/Textures/Wall.jpg");
	wolf_load_texture(1, "Assets/Textures/Floor.jpg");

	glViewport(0, 0, (GLsizei) 640, (GLsizei) 480);

	unsigned int time_delta = 0;

	while (running) {
		unsigned int frame_start, frame_end;

		frame_start = SDL_GetTicks();

		wolf_input();

		wolf_update(time_delta);

		wolf_frame(&position, &direction, angle);

		SDL_GL_SwapWindow(window);

		frame_end = SDL_GetTicks();

		time_delta = frame_end - frame_start;
	}

	SDL_GL_DeleteContext(context);

	SDL_DestroyWindow(window);

	SDL_Quit();

	return 0;
}
开发者ID:Clever-Boy,项目名称:wolf,代码行数:61,代码来源:wolf.c

示例15: SDL_DestroyWindow

Graphics::~Graphics() {
    SDL_DestroyWindow(this->_window);
}
开发者ID:CoreyHickson,项目名称:cavestory,代码行数:3,代码来源:graphics.cpp


注:本文中的SDL_DestroyWindow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。