int main(int argc, const char * const argv[])
{
	sf::Event           e;
	sf::Window          win;
	sf::VideoMode       vm;
	std::stringstream   win_title;
	sf::ContextSettings cs;

	win_title<<APP_TITLE<<" "<<APP_VERSION;
	vm.width        = WIDTH;
	vm.height       = HEIGHT;
	vm.bitsPerPixel = 32;
	cs.depthBits    = 24;
	cs.stencilBits  = 8;
	win.create(vm, win_title.str(), sf::Style::Default, cs);
	win.setFramerateLimit(60);
	win.setVerticalSyncEnabled(g_vsync);
	win.setActive();
	setup_render_state();
	while(g_run) {
		while (win.pollEvent(e))
			handle_event(e);
		render_scene();
		win.display();
	}
	win.close();

	return 0;
}
int main(int argc, const char * const argv[])
{
	sf::Event     e;
	sf::Window    win;
	sf::VideoMode vm;
	sf::Clock     c;
	std::string   win_title;

	win_title       = "Pointsz";
	vm.width        = win_w;
	vm.height       = win_h;
	vm.bitsPerPixel = 32;
	win.create(vm, win_title);
	win.setFramerateLimit(60);
	win.setVerticalSyncEnabled(g_vsync);
	win.setActive();
	setup_render_state();
	c.restart();
	while(g_run) {
		while (win.pollEvent(e))
			handle_event(e);
		render_scene();
		win.display();
	}
	win.close();

	return 0;
}
Example #3
0
/**
 * Render a glBitmap by drawing a textured quad
 */
static void
draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
                 GLsizei width, GLsizei height,
                 struct pipe_sampler_view *sv,
                 const GLfloat *color)
{
   struct st_context *st = st_context(ctx);
   struct pipe_context *pipe = st->pipe;
   const float fb_width = (float) st->state.fb_width;
   const float fb_height = (float) st->state.fb_height;
   const float x0 = (float) x;
   const float x1 = (float) (x + width);
   const float y0 = (float) y;
   const float y1 = (float) (y + height);
   float sLeft = 0.0f, sRight = 1.0f;
   float tTop = 0.0f, tBot = 1.0f - tTop;
   const float clip_x0 = x0 / fb_width * 2.0f - 1.0f;
   const float clip_y0 = y0 / fb_height * 2.0f - 1.0f;
   const float clip_x1 = x1 / fb_width * 2.0f - 1.0f;
   const float clip_y1 = y1 / fb_height * 2.0f - 1.0f;

   /* limit checks */
   {
      /* XXX if the bitmap is larger than the max texture size, break
       * it up into chunks.
       */
      GLuint MAYBE_UNUSED maxSize =
         1 << (pipe->screen->get_param(pipe->screen,
                                       PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
      assert(width <= (GLsizei) maxSize);
      assert(height <= (GLsizei) maxSize);
   }

   setup_render_state(ctx, sv, color, false);

   /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
   z = z * 2.0f - 1.0f;

   if (sv->texture->target == PIPE_TEXTURE_RECT) {
      /* use non-normalized texcoords */
      sRight = (float) width;
      tBot = (float) height;
   }

   if (!st_draw_quad(st, clip_x0, clip_y0, clip_x1, clip_y1, z,
                     sLeft, tBot, sRight, tTop, color, 0)) {
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBitmap");
   }

   restore_render_state(ctx);

   /* We uploaded modified constants, need to invalidate them. */
   st->dirty |= ST_NEW_FS_CONSTANTS;
}
Example #4
0
/**
 * Called via ctx->Driver.DrawAtlasBitmap()
 */
static void
st_DrawAtlasBitmaps(struct gl_context *ctx,
                    const struct gl_bitmap_atlas *atlas,
                    GLuint count, const GLubyte *ids)
{
    struct st_context *st = st_context(ctx);
    struct pipe_context *pipe = st->pipe;
    struct st_texture_object *stObj = st_texture_object(atlas->texObj);
    struct pipe_sampler_view *sv;
    /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
    const float z = ctx->Current.RasterPos[2] * 2.0f - 1.0f;
    const float *color = ctx->Current.RasterColor;
    const float clip_x_scale = 2.0f / st->state.framebuffer.width;
    const float clip_y_scale = 2.0f / st->state.framebuffer.height;
    const unsigned num_verts = count * 4;
    const unsigned num_vert_bytes = num_verts * sizeof(struct st_util_vertex);
    struct st_util_vertex *verts;
    struct pipe_vertex_buffer vb = {0};
    unsigned i;

    if (!st->bitmap.cache) {
        init_bitmap_state(st);
    }

    st_flush_bitmap_cache(st);

    st_validate_state(st, ST_PIPELINE_RENDER);
    st_invalidate_readpix_cache(st);

    sv = st_create_texture_sampler_view(pipe, stObj->pt);
    if (!sv) {
        _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCallLists(bitmap text)");
        return;
    }

    setup_render_state(ctx, sv, color, true);

    vb.stride = sizeof(struct st_util_vertex);

    u_upload_alloc(st->uploader, 0, num_vert_bytes, 4,
                   &vb.buffer_offset, &vb.buffer, (void **) &verts);

    /* build quads vertex data */
    for (i = 0; i < count; i++) {
        const GLfloat epsilon = 0.0001F;
        const struct gl_bitmap_glyph *g = &atlas->glyphs[ids[i]];
        const float xmove = g->xmove, ymove = g->ymove;
        const float xorig = g->xorig, yorig = g->yorig;
        const float s0 = g->x, t0 = g->y;
        const float s1 = s0 + g->w, t1 = t0 + g->h;
        const float x0 = IFLOOR(ctx->Current.RasterPos[0] - xorig + epsilon);
        const float y0 = IFLOOR(ctx->Current.RasterPos[1] - yorig + epsilon);
        const float x1 = x0 + g->w, y1 = y0 + g->h;
        const float clip_x0 = x0 * clip_x_scale - 1.0f;
        const float clip_y0 = y0 * clip_y_scale - 1.0f;
        const float clip_x1 = x1 * clip_x_scale - 1.0f;
        const float clip_y1 = y1 * clip_y_scale - 1.0f;

        /* lower-left corner */
        verts->x = clip_x0;
        verts->y = clip_y0;
        verts->z = z;
        verts->r = color[0];
        verts->g = color[1];
        verts->b = color[2];
        verts->a = color[3];
        verts->s = s0;
        verts->t = t0;
        verts++;

        /* lower-right corner */
        verts->x = clip_x1;
        verts->y = clip_y0;
        verts->z = z;
        verts->r = color[0];
        verts->g = color[1];
        verts->b = color[2];
        verts->a = color[3];
        verts->s = s1;
        verts->t = t0;
        verts++;

        /* upper-right corner */
        verts->x = clip_x1;
        verts->y = clip_y1;
        verts->z = z;
        verts->r = color[0];
        verts->g = color[1];
        verts->b = color[2];
        verts->a = color[3];
        verts->s = s1;
        verts->t = t1;
        verts++;

        /* upper-left corner */
        verts->x = clip_x0;
        verts->y = clip_y1;
        verts->z = z;
        verts->r = color[0];
        verts->g = color[1];
        verts->b = color[2];
        verts->a = color[3];
        verts->s = s0;
        verts->t = t1;
        verts++;

        /* Update the raster position */
        ctx->Current.RasterPos[0] += xmove;
        ctx->Current.RasterPos[1] += ymove;
    }

    u_upload_unmap(st->uploader);

    cso_set_vertex_buffers(st->cso_context,
                           cso_get_aux_vertex_buffer_slot(st->cso_context),
                           1, &vb);

    cso_draw_arrays(st->cso_context, PIPE_PRIM_QUADS, 0, num_verts);

    restore_render_state(ctx);

    pipe_resource_reference(&vb.buffer, NULL);

    pipe_sampler_view_reference(&sv, NULL);

    /* We uploaded modified constants, need to invalidate them. */
    st->dirty |= ST_NEW_FS_CONSTANTS;
}