From: John Tsiombikas Date: Thu, 15 Sep 2022 15:55:22 +0000 (+0300) Subject: added vbo/varr points method X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=glpixels;a=commitdiff_plain;h=6ade6e757b28dcefeabde6d2254005c64f50ed26 added vbo/varr points method --- diff --git a/glpixels.c b/glpixels.c index b04ee88..cae9499 100644 --- a/glpixels.c +++ b/glpixels.c @@ -2,10 +2,11 @@ #include #include #include +#define GL_GLEXT_PROTOTYPES 1 #include enum { - MODE_VERTEX, + MODE_POINTS, MODE_DRAWPIX, MODE_TEXQUAD, MODE_TEXTRI, @@ -25,8 +26,14 @@ int max_xscroll, max_yscroll; #define IMG_W 1024 #define IMG_H 1024 unsigned int img[IMG_W * IMG_H]; +float *varr, *carr; +unsigned int vbo_pos, vbo_col; +int varr_sz, carr_sz; + +int mode = MODE_POINTS; + +int have_vbo = 1; /* TODO */ -int mode = MODE_DRAWPIX; int main(int argc, char **argv) { @@ -53,6 +60,7 @@ int init(void) int i, j, xor, r, g, b; unsigned int *ptr; unsigned int tex; + float *vptr; ptr = img; for(i=0; i> 8) & 0xff; + int b = (start[j] >> 16) & 0xff; + vptr[0] = r / 255.0f; + vptr[1] = g / 255.0f; + vptr[2] = b / 255.0f; + vptr += 3; + } + start += IMG_W; + } + + if(have_vbo) { + glBindBuffer(GL_ARRAY_BUFFER, vbo_pos); + glVertexPointer(2, GL_FLOAT, 0, 0); + glBindBuffer(GL_ARRAY_BUFFER, vbo_col); + glBufferSubData(GL_ARRAY_BUFFER, 0, carr_sz, carr); + glColorPointer(3, GL_FLOAT, 0, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + } else { + glVertexPointer(2, GL_FLOAT, 0, varr); + glColorPointer(3, GL_FLOAT, 0, carr); + } + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glDrawArrays(GL_POINTS, 0, win_width * win_height); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); break; case MODE_DRAWPIX: /* draw with glDrawPixels */ - start = img + yoffs * IMG_W + xoffs; glDrawPixels(win_width, win_height, GL_RGBA, GL_UNSIGNED_BYTE, start); break; @@ -120,6 +192,10 @@ void reshape(int x, int y) { glViewport(0, 0, x, y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, x, 0, y, -1, 1); + win_width = x; win_height = y; max_xscroll = IMG_W - win_width;