1 /* Display a cleared blue window. This demo has no dependencies on
2 * any utility code, just the graw interface and gallium.
8 static struct graw_info info
;
10 static const int WIDTH
= 300;
11 static const int HEIGHT
= 300;
19 static boolean FlatShade
= FALSE
;
22 static struct vertex vertices
[3] =
25 { 0.0f
, -0.9f
, 0.0f
, 1.0f
},
26 { 1.0f
, 0.0f
, 0.0f
, 1.0f
}
29 { -0.9f
, 0.9f
, 0.0f
, 1.0f
},
30 { 0.0f
, 1.0f
, 0.0f
, 1.0f
}
33 { 0.9f
, 0.9f
, 0.0f
, 1.0f
},
34 { 0.0f
, 0.0f
, 1.0f
, 1.0f
}
39 static void set_vertices( void )
41 struct pipe_vertex_element ve
[2];
42 struct pipe_vertex_buffer vbuf
;
45 memset(ve
, 0, sizeof ve
);
47 ve
[0].src_offset
= Offset(struct vertex
, position
);
48 ve
[0].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
49 ve
[1].src_offset
= Offset(struct vertex
, color
);
50 ve
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
52 handle
= info
.ctx
->create_vertex_elements_state(info
.ctx
, 2, ve
);
53 info
.ctx
->bind_vertex_elements_state(info
.ctx
, handle
);
55 memset(&vbuf
, 0, sizeof vbuf
);
57 vbuf
.stride
= sizeof( struct vertex
);
58 vbuf
.buffer_offset
= 0;
59 vbuf
.buffer
= pipe_buffer_create_with_data(info
.ctx
,
60 PIPE_BIND_VERTEX_BUFFER
,
65 info
.ctx
->set_vertex_buffers(info
.ctx
, 0, 1, &vbuf
);
69 static void set_vertex_shader( void )
76 "DCL OUT[0], POSITION\n"
78 " 0: MOV OUT[1], IN[1]\n"
79 " 1: MOV OUT[0], IN[0]\n"
82 handle
= graw_parse_vertex_shader(info
.ctx
, text
);
83 info
.ctx
->bind_vs_state(info
.ctx
, handle
);
87 static void set_fragment_shader( void )
92 "DCL IN[0], COLOR, LINEAR\n"
94 " 0: MOV OUT[0], IN[0]\n"
97 handle
= graw_parse_fragment_shader(info
.ctx
, text
);
98 info
.ctx
->bind_fs_state(info
.ctx
, handle
);
102 static void draw( void )
104 union pipe_color_union clear_color
= { {1,0,1,1} };
106 info
.ctx
->clear(info
.ctx
, PIPE_CLEAR_COLOR
, &clear_color
, 0, 0);
107 util_draw_arrays(info
.ctx
, PIPE_PRIM_TRIANGLES
, 0, 3);
108 info
.ctx
->flush(info
.ctx
, NULL
, 0);
110 graw_save_surface_to_file(info
.ctx
, info
.color_surf
[0], NULL
);
112 graw_util_flush_front(&info
);
116 static void init( void )
118 if (!graw_util_create_window(&info
, WIDTH
, HEIGHT
, 1, FALSE
))
121 graw_util_default_state(&info
, FALSE
);
124 struct pipe_rasterizer_state rasterizer
;
126 memset(&rasterizer
, 0, sizeof rasterizer
);
127 rasterizer
.cull_face
= PIPE_FACE_NONE
;
128 rasterizer
.half_pixel_center
= 1;
129 rasterizer
.bottom_edge_rule
= 1;
130 rasterizer
.flatshade
= FlatShade
;
131 rasterizer
.depth_clip
= 1;
132 handle
= info
.ctx
->create_rasterizer_state(info
.ctx
, &rasterizer
);
133 info
.ctx
->bind_rasterizer_state(info
.ctx
, handle
);
137 graw_util_viewport(&info
, 0, 0, WIDTH
, HEIGHT
, 30, 1000);
141 set_fragment_shader();
144 static void args(int argc
, char *argv
[])
148 for (i
= 1; i
< argc
; ) {
149 if (graw_parse_args(&i
, argc
, argv
)) {
152 else if (strcmp(argv
[i
], "-f") == 0) {
157 printf("Invalid arg %s\n", argv
[i
]);
163 int main( int argc
, char *argv
[] )
168 graw_set_display_func( draw
);