void Offscreen::set(const Texture & in) { //DJV_DEBUG("Offscreen::set"); fbo_check(); DJV_DEBUG_GL(glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, in.id(), 0)); }
void board_init(const GLuint aWidth, const GLuint aKnightRow, const GLuint aKnightCol) { board__width = aWidth; // number of cycles it takes to finish the computation: // // (3 cycles per knight) * (number of knights) // // the -1 is because the initial knight is not determined // at runtime, so we save one cycle of processing. // // see EXPORT_DELAY in the "naive.cg.erb" file for details. // board__numCycles = 3 * board__area; printf("\nThe tour should take %lu cycles to complete.\n", board__numCycles); // generate the board data if((board__data = (float*)malloc(4*board__area*sizeof(float))) == NULL) { printf("\n*** out of memory allocating board__data ***\n"); exit(2); } unsigned addr = 0; for(unsigned row = 0; row < board__width; row++) { for (unsigned col = 0; col < board__width; col++) { // red channel board__data[addr++] = ( // set initial position of knight row == aKnightRow && col == aKnightCol ) ? 1 : 0; // green channel board__data[addr++] = 0; // blue channel board__data[addr++] = 0; // alpha channel board__data[addr++] = 8; // 8 is MOVE_NONE (see naive.cg.erb for details); all cells should have next move = NONE initially, because only the knight makes the "next move" desicison at *runtime* } } // Generate, set up, and bind the texture texture_new(&board__computeTexture, board__width, board__width, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA32F_ARB, NULL); // initialize the FBO fbo_init(board__width, board__width); // Attach the texture to the framebuffer object glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, board__computeTexture, 0); // Check the FBO for completeness fbo_check(); // generate texture for board display texture_new(&board__displayTexture, board__width, board__width, GL_TEXTURE_2D, GL_RGBA, NULL); // generate OpenGL display lists to speed up rendering board__gridDisplayList = glGenLists(1); glNewList(board__gridDisplayList, GL_COMPILE); // draw board outline (grid) float step = 2.0 / board__width; float cell; glBegin(GL_LINES); // draw rows for (cell = -1 + step; cell < board__width; cell += step) { glVertex3f(-1, cell, -1); glVertex3f(1, cell, -1); } // draw columns for (cell = -1 + step; cell < board__width; cell += step) { glVertex3f(cell, -1, -1); glVertex3f(cell, 1, -1); } glEnd(); glEndList(); }