Exemplo n.º 1
1
/*
 * @overload create(window)
 *   Create an OpenGL context for use with an OpenGL window, and make it
 *   current.
 *
 *   @param window [SDL2::Window] the window associate with a new context
 *   @return [SDL2::GL::Context]
 *
 *   @see #delete
 *
 *   @example
 *
 *     SDL2.init(SDL2::INIT_EVERYTHING)
 *     # You need to create a window with `OPENGL' flag
 *     window = SDL2::Window.create("testgl", 0, 0, WINDOW_W, WINDOW_H,
 *                                  SDL2::Window::Flags::OPENGL)
 *                                  
 *     # Create a OpenGL context attached to the window
 *     context = SDL2::GL::Context.create(window)
 *
 *     # You can use OpenGL functions
 *          :
 *          
 *     # Delete the context after using OpenGL functions
 *     context.destroy
 */
static VALUE GLContext_s_create(VALUE self, VALUE window)
{
    SDL_GLContext context = SDL_GL_CreateContext(Get_SDL_Window(window));
    if (!context)
        SDL_ERROR();

    return (current_context = GLContext_new(context));
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
#pragma unused(argc, argv)
  SDL_Window *window;
  SDL_Renderer *renderer;
  int done = 0;
  SDL_Event event;
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    SDL_ERROR(SDL_Init);
    return 1;
  }
  if (SDL_CreateWindowAndRenderer(200, 200, 0, &window, &renderer) == -1) {
    SDL_ERROR(SDL_SetVideoMode);
    SDL_Quit();
    return 1;
  }
  while (!done) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT ||
	  (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q && (event.key.keysym.mod == KMOD_LGUI || event.key.keysym.mod == KMOD_RGUI))) {
	done = !0;
      }
    }
    SDL_Delay(0);
  }
  SDL_Delay(500);
  SDL_Quit();
  return 0;
}
Exemplo n.º 3
0
int     load_image(shooter_ctx* ctx, char *name, asset** a)
{
    SDL_Surface* loadedImage = NULL;
    int          ret;

    *a = malloc(sizeof(**a));
    if (!(*a)) return (ENOMEM);
    loadedImage = IMG_Load(name);
    if (loadedImage != NULL) {
        (*a)->texture = SDL_CreateTextureFromSurface(ctx->renderer, loadedImage);
        SDL_FreeSurface(loadedImage);
    }
    else {
        IMG_ERROR("IMG_Load");
        return (1);
    }

    if (!((*a)->texture)) {
        SDL_ERROR("SDL_CreateTextureFromSurface");
        return (1);
    }

    ret = SDL_QueryTexture((*a)->texture, NULL, NULL, &((*a)->sx), &((*a)->sy));
    if (ret) {
        SDL_ERROR("SDL_QueryTexture");
        return (ret);
    }
    return (0);

}
Exemplo n.º 4
0
bool Window::setFullscreen(const bool isFullscreen)
{
	m_isFullscreen = isFullscreen;
	
	SDL_SetWindowFullscreen(m_sdlWindow, m_isFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
	SDL_ERROR("Window::setFullscreen()");
	
	return true;
}
Exemplo n.º 5
0
uint16_t Window::getHeight() const
{
	int w, h;
	
	SDL_GetWindowSize(m_sdlWindow, &w, &h);
	SDL_ERROR("Window::getHeight()");

	return (uint16_t)h;
}
Exemplo n.º 6
0
bool Window::setTitle(const std::string & setTitle)
{
	m_title = setTitle;
	
	SDL_SetWindowTitle(m_sdlWindow, m_title.c_str());
	SDL_ERROR("Window::setTitle()");
	
	return true;
}
Exemplo n.º 7
0
void project(IMutableHypergraph<Arc>* hg, ProjectType projection) {
  switch (projection) {
    case kProject_Input:
      hg->projectInput();
      return;
    case kProject_Output:
      hg->projectOutput();
      return;
    default:
      SDL_ERROR(Hypergraph.Project, "unknown projection type: " << to_string_impl(projection));
  }
}
Exemplo n.º 8
0
Arquivo: wav.cpp Projeto: iwadon/junk
bool Wav::ParseData(const void *data, size_t size)
{
  SDL_RWops *f = SDL_RWFromConstMem(data, size);
  if (f == NULL) {
    SDL_ERROR("SDL_RWFromConstMem failed");
    return false;
  }

  bool ret = ParseData(f);

  SDL_RWclose(f);

  return false;
}
Exemplo n.º 9
0
Arquivo: wav.cpp Projeto: iwadon/junk
bool Wav::LoadFile(const SP &filename)
{
  SDL_RWops *f = SDL_RWFromFile(filename.c_str(), "rb");
  if (f == NULL) {
    SDL_ERROR("SDL_RWFromFile failed");
    return false;
  }

  bool ret = ParseData(f);

  SDL_RWclose(f);

  return ret;
}
Exemplo n.º 10
0
void Sprite::draw()
{
  if (texture == NULL || texture->texture == NULL) {
    return;
  }

  SDL_Rect dst;
  dst.x = 0;
  dst.y = 0;
  dst.w = texture->width;
  dst.h = texture->height;

#ifdef ENABLE_OPENGL
  glPushMatrix();
  glTranslatef(pos.x, pos.y, 0.0f);
  glRotatef(rot, 0.0f, 0.0f, 1.0f);
  glTranslatef(-(texture->width * scale / 2.0f), -(texture->height * scale / 2.0f), 0.0f);
  glScalef(scale, scale, 1.0f);
  if (SDL_RenderCopy(renderer, texture->texture, &rect, &dst) == -1) {
    SDL_ERROR(SDL_RenderCopy);
  }
  glPopMatrix();
#endif
}
Exemplo n.º 11
0
int main(void) {
    SDL_Event event;
    SDL_Renderer *renderer;
    SDL_Window *window;
    int i;

    SDL_ERROR(SDL_Init(SDL_INIT_VIDEO));
    SDL_ERROR(SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_WIDTH, 0, &window, &renderer));
    SDL_ERROR(SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0));
    SDL_ERROR(SDL_RenderClear(renderer));
    SDL_ERROR(SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255));
    for (i = 0; i < WINDOW_WIDTH; ++i)
        SDL_ERROR(SDL_RenderDrawPoint(renderer, i, i));
    SDL_RenderPresent(renderer);
    while (1) {
        if (SDL_PollEvent(&event) && event.type == SDL_QUIT)
            break;
    }
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return EXIT_SUCCESS;
}
Exemplo n.º 12
0
void assertion_failed_msg(char const * expr, char const* msg, char const * function, char const * file, long line) {
  std::stringstream ss;
  ss << msg << "- Assertion failure:" << expr << ", in " << file << "::" << function << "at line number: " << line;
  SDL_ERROR(Assert, ss.str());
}