示例#1
0
// Blit the output bitmap to the screen and flip the buffer if double buffered
void drawFrame(void)
{
	SDL_Rect dstRect;
	
	dstRect.x = 0;
	dstRect.y = 0;
	dstRect.w = GB_DISPLAY_WIDTH * scaleFactor;
	dstRect.h = GB_DISPLAY_HEIGHT * scaleFactor;

	if (showTilemap)
	{
		drawTilemap(gbSurface);
	}

	if (SDL_SoftStretch(gbSurface, NULL, screen, &dstRect) != 0)
	{
		printf("ERROR: Cannot blit surface\n");
		exit(0);
	}
	
    if (SDL_Flip(screen) != 0)
	{
		printf("ERROR: Could not flip framebuffer\n");
	}
    
    frames++;
}
示例#2
0
文件: renderer.cpp 项目: swm93/nssj
void Renderer::render(GLFWwindow *window, double t, double dt)
{
    Vf2 projection_dims = getProjectionDimensions(gamestate->window_size.x, gamestate->window_size.y);
    M4x4<float> view_mat = getViewMatrix();
    // TODO(scott): this should be cached and not recalculated every frame
    M4x4<float> projection_mat = M4x4<float>::orthographicProj(0, projection_dims.x, 0, projection_dims.y, -1, 1);
    
    glViewport(0, 0, gamestate->window_size.x, gamestate->window_size.y);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, projection_dims.x, 0, projection_dims.y, -1, 1);

    glMatrixMode(GL_MODELVIEW);
    
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    
    glEnable(GL_TEXTURE_2D);

    glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);

    glTexCoordPointer(num_texcoord_vertex, GL_FLOAT, sizeof(GLfloat) * (num_position_vertex + num_texcoord_vertex), (float*)(sizeof(GLfloat)*num_position_vertex));
    glVertexPointer(num_position_vertex, GL_FLOAT, sizeof(GLfloat) * (num_position_vertex + num_texcoord_vertex), NULL);
    
    drawTilemap(view_mat, projection_mat);
    drawEntities(view_mat, projection_mat);
    
    glDisable(GL_TEXTURE_2D);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    
    glfwSwapBuffers(window);
    glfwPollEvents();
}