Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Store white noise background pixels in RGBA format
Browse files Browse the repository at this point in the history
  • Loading branch information
cstawarz committed Jan 26, 2011
1 parent 0cc4291 commit f10a879
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions WhiteNoiseBackground/WhiteNoiseBackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ void WhiteNoiseBackground::load(shared_ptr<StimulusDisplay> display) {

glGenBuffers(1, &(buffers[i]));
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[i]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, (width * height * sizeof(PixelType)), NULL, GL_DYNAMIC_DRAW);
glBufferData(GL_PIXEL_UNPACK_BUFFER,
(width * height * sizeof(PixelType) * componentsPerPixel),
NULL,
GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}

Expand Down Expand Up @@ -76,7 +79,7 @@ void WhiteNoiseBackground::draw(shared_ptr<StimulusDisplay> display) {
glWindowPos2i(0, 0);

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[index]);
glDrawPixels(currentDims.first, currentDims.second, GL_LUMINANCE, PIXEL_TYPE, (GLvoid *)0);
glDrawPixels(currentDims.first, currentDims.second, PIXEL_FORMAT, PIXEL_TYPE, (GLvoid *)0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

glPopClientAttrib();
Expand All @@ -100,8 +103,13 @@ void WhiteNoiseBackground::randomizePixels() {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[i]);
PixelType *pixels = (PixelType *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);

for (size_t i = 0; i < (currentDims.first * currentDims.second); i++) {
pixels[i] = randDist();
for (size_t i = 0; i < (currentDims.first * currentDims.second * componentsPerPixel); i++) {
PixelType randVal = randDist();
for (size_t j = 0; j < componentsPerPixel - 1; j++) {
pixels[i] = randVal;
i++;
}
pixels[i] = 1.0;
}

glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
Expand Down
2 changes: 2 additions & 0 deletions WhiteNoiseBackground/WhiteNoiseBackground.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class WhiteNoiseBackground : public Stimulus {
WhiteNoiseBackground(const WhiteNoiseBackground &other);

typedef std::pair<GLint, GLint> DisplayDimensions;
#define PIXEL_FORMAT GL_RGBA
#define PIXEL_TYPE GL_FLOAT
typedef GLfloat PixelType;
static const GLint componentsPerPixel = 4;

std::map<int, DisplayDimensions> dims;
std::map<int, GLuint> buffers;
Expand Down

0 comments on commit f10a879

Please sign in to comment.