Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing large numbers of pixels in OpenGL

I've been working on some sound processing code and now I'm doing some visualizations. I finished making a spectrogram spectrogram, but how I am drawing it is too slow.

I'm using OpenGL to do 2D drawing, which has made searching for help more difficult. Also I am very new to OpenGL, so I don't know the standard way things are done.

I am storing the r,g,b values for each pixel in a large matrix. Each time I get a small sound segment, I process it and convert it to column of pixels. Everything is shifted to the left 1 pixel, and the new line is put at the end.

Each time I redraw, I am looping through setting the color and drawing each pixel individually, which seems like a horribly inefficient way to do this.

Is there a better way to do this? Is there some method for simply shifting a bunch of pixels over?

like image 569
MattRS Avatar asked Nov 06 '10 01:11

MattRS


1 Answers

They are many ways to improve your drawing speed. The simplest would be to allocate a an RGB texture that you will draw using a screen aligned texture quad. Each time that you want to draw a new line you can use glTexSubImage2d to a load a new subset of the texture and then you redraw the quad.

like image 139
user473816 Avatar answered Oct 19 '22 23:10

user473816