Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Calculating all pixels in a frame

  1. #11
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    17
    Sorry, I've been away for a while. I've just started again. This is what I got so far:

    Code :
    int main() {
    	GLuint BUFFER;
    	glGenBuffers(1,&BUFFER);
    	glBindBuffer(GL_READ_FRAMEBUFFER,BUFFER);
    	glBufferData(GL_PIXEL_UNPACK_BUFFER,WIDTH*HEIGHT,NULL,GL_DRAW_BUFFER);
    	unsigned char* buffer_map = (unsigned char*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER,0,WIDTH*HEIGHT,GL_MAP_WRITE_BIT);
     
        bool running = true;
        while (running) {
            if (isFinished())  { running = fallse; }
     
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	fill_buffer(buffer_map, WIDTH, HEIGHT,objects);
    	glBlitFramebuffer(0,0,WIDTH,HEIGHT,0,0,WIDTH,HEIGHT,GL_COLOR_BUFFER_BIT,GL_FILTER);
     
            window.display();
        }
     
        return 0;
    }
     
    void fill_buffer(unsigned char* buffer, unsigned int width, unsigned int height) {
    	for (unsigned int pixelX = 0; i < width; ++pixelX) {
    		for (unsigned int pixelY = 0; j < height; ++pixelY) {
    			buffer[pixelX*width+pixelY] = calc_pixel(i,j) ? 1 : 0;	// writing a value of 1 to the buffer for test reason
    			}
    		}
    	}
     
    	// buffer only contains red values
    	glDrawPixels(width,height,GL_RED,GL_UNSIGNED_BYTE,buffer);
    }

    Note that this is only the essential portion of the code. I don't know if this looks good or if this might work?

    I wanted to test it, but I couldn't compile it, becaus I got "unresolved external symbol" for some functions. I know what that means: that there is no implementation available for some of the functions I'm using.
    I get this error with: glewBindBuffer, glewBufferData, glewGenBuffers, glewBlitFramebuffer, glewMapBufferRange
    So at the moment I'm figuring out why my glew isn't properly working... Any suggestions are welcome, but off course it's a difficult for you to guess what might be wrong.
    Any suggestions on the could would be greatly appreciated.

  2. #12
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    17
    Ok, I solved the unresolved symbol problem. Stupid of me...

    Anyway, I started the code, and I got an acces violation on the second line:

    Code :
    GLuint BUFFER;
    glGenBuffers(1,&BUFFER);

    I don't really see how I could have done something wrong in these lines, but apperantly I did. So can someone please point it out to me?

  3. #13
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    I don't see the part of your code where you initialize your OpenGL loading library. Or OpenGL for that matter. You should do that before calling OpenGL functions.

  4. #14
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    17
    I was just about to edit my post. so I didn't have any initation code...

    Anyway, what I found on your (link but I just had found that myself):
    Code :
    glewExperimental=GL_TRUE; 
    	GLenum err=glewInit();
    	if(err!=GLEW_OK)
    	{
    		//Problem: glewInit failed, something is seriously wrong.
    		cout<<"glewInit failed, aborting."<<endl;
    	}
    So when I run this I get an error code from the glewInit() function. So I'm just looking around on google what possible reasons are.

    edit: found it and my error says: "error: missing GL version"

  5. #15
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    17
    So the "error: missing GL version" is fixed. I created my openGL context after the glewinit. didn't notice...
    Anyway, to continue, this call:

    Code :
    unsigned char* buffer_map = (unsigned char*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER,0,WIDTH*HEIGHT,GL_MAP_WRITE_BIT);
    returns a NULL object. so the mapping didn't work I assume?

    edit:
    I figured I just used wrong parameters? So I tried some different ones, but none work, this is the code right now:
    Code :
    	glGenBuffers(1,&BUFFER);
    	glBindBuffer(GL_READ_FRAMEBUFFER,BUFFER);
    	glBufferData(GL_PIXEL_UNPACK_BUFFER,WIDTH*HEIGHT,NULL,GL_DYNAMIC_DRAW);
    	unsigned char* buffer_map = (unsigned char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
    Last edited by genzm19; 06-11-2013 at 02:57 AM.

  6. #16
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    17
    Just one more paramtere edit and it worked:
    Code :
    glGenBuffers(1,&BUFFER);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER,BUFFER);
    glBufferData(GL_PIXEL_UNPACK_BUFFER,WIDTH*HEIGHT,NULL,GL_DYNAMIC_DRAW);
    unsigned char* buffer_map = (unsigned char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);

    Now I'm able to fill the buffer very fast. Much faster than I really expected.

    Now just as a test case, I filled the buffer with all 1 values (being completely red).
    This is the code:
    Code :
    for (unsigned int pixelX = 0; pixelX < width; ++pixelX) {
    	for (unsigned int pixelY = 0; pixelY < height; ++pixelY) {
    		buffer[pixelX*width+pixelY] = 1;
    	}
    }
     
    glDrawPixels(width,height,GL_RED,GL_UNSIGNED_BYTE,buffer);
     
    glBlitFramebuffer(0,0,WIDTH,HEIGHT,0,0,WIDTH,HEIGHT,GL_COLOR_BUFFER_BIT,GL_FILTER);

    but this gives me a completley black screen instead of completley red. Any suggestions?
    I've seen some examples online, where they use a 2D array (instead of a 1D array) to store the pixel data. Since multiple rows of an array are just stored one after the other, I don't think this will make a difference, but just to be sure, can someone confirm this?
    Last edited by genzm19; 06-11-2013 at 04:20 AM.

  7. #17
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    17
    As the current problem of this thread is no longer related with the subforum and the title topic, I've created a new thread in the right forum.
    Anyway, a great thanks to Alfonse Reinheart, who has helped me with the problem and showed me some very interessting possibilities of opengl

    http://www.opengl.org/discussion_boa...24#post1251624

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •