void drawMesh(Blitz3DMESHChunk* mesh) { unsigned int iter; unsigned int texCoordCount; unsigned int texCoordComponentCount; int meshBrushId; Blitz3DVRTSChunk* vrtsChunk; Blitz3DBRUSChunk* brusChunk; meshBrushId = getBrushIdFromMESHChunk(mesh); brusChunk = getBRUSChunkFromBB3DChunk( getBB3DChunkFromFile(b3dTest) ); vrtsChunk = getVRTSChunkFromMESHChunk(mesh); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, getVertexArrayFromVRTSChunk(vrtsChunk)); if (normalArrayPresentInVRTSChunk(vrtsChunk)) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, getNormalArrayFromVRTSChunk(vrtsChunk)); } if (colorArrayPresentInVRTSChunk(vrtsChunk)) { glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_FLOAT, 0, getColorArrayFromVRTSChunk(vrtsChunk)); } texCoordCount = getTexCoordArrayCountFromVRTSChunk(vrtsChunk); texCoordComponentCount = getTexCoordArrayComponentCountFromVRTSChunk(vrtsChunk); glClientActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(texCoordComponentCount, GL_FLOAT, 0, getTexCoordArrayEntryFromVRTSChunk(vrtsChunk, 0)); glClientActiveTextureARB(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(texCoordComponentCount, GL_FLOAT, 0, getTexCoordArrayEntryFromVRTSChunk(vrtsChunk, 1)); for (iter = 0; iter < getTRISChunkArrayCountFromMESHChunk(mesh); iter++) { Blitz3DTRISChunk* trisChunk; Blitz3DBrush* brush; int trisBrushId; trisChunk = getTRISChunkArrayEntryFromMESHChunk(mesh, iter); trisBrushId = getBrushIdFromTRISChunk(trisChunk); if (trisBrushId == -1) trisBrushId = meshBrushId; brush = getBrushArrayEntryFromBRUSChunk(brusChunk, trisBrushId); /* commentary: not sure why the brush textures seem reversed here! */ glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, textures[getTextureIdArrayEntryFromBrush(brush, 1)]); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, textures[getTextureIdArrayEntryFromBrush(brush, 0)]); glDrawElements(GL_TRIANGLES, 3 * getTriangleCountFromTRISChunk(trisChunk), GL_UNSIGNED_INT, getTriangleIndexArrayFromTRISChunk(trisChunk)); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glClientActiveTextureARB(GL_TEXTURE0_ARB); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTextureARB(GL_TEXTURE1_ARB); glDisableClientState(GL_TEXTURE_COORD_ARRAY); }
real DrawVoronoi(real* xx) { int i,j; real fEnergy = 1e20; GLfloat *buffer_screen = new GLfloat[screenwidth*screenheight*4]; ////////////////////////////////////////////// // First pass - Render the initial sites // ////////////////////////////////////////////// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FB_objects); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Processed_Texture[0], 0); CheckFramebufferStatus(); glClearColor(-1, -1, -1, -1); glClear(GL_COLOR_BUFFER_BIT); glDrawBuffer(fbo_attachments[0]); cgGLEnableProfile(VertexProfile); cgGLEnableProfile(FragmentProfile); cgGLBindProgram(VP_DrawSites); cgGLBindProgram(FP_DrawSites); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(1, screenwidth+1, 1, screenheight+1); glViewport(1, 1, screenwidth, screenheight); DrawSites(xx, NULL); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); Current_Buffer = 1; ///////////////////////////////////// // Second pass - Flood the sites // ///////////////////////////////////// cgGLBindProgram(VP_Flood); cgGLBindProgram(FP_Flood); if (VP_Flood_Size != NULL) cgSetParameter2f(VP_Flood_Size, screenwidth, screenheight); bool ExitLoop = false; bool SecondExit; int steplength;; SecondExit = (additional_passes==0); bool PassesBeforeJFA; PassesBeforeJFA = (additional_passes_before>0); if (PassesBeforeJFA) steplength = pow(2.0, (additional_passes_before-1)); else steplength = (screenwidth>screenheight ? screenwidth : screenheight)/2; while (!ExitLoop) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[Current_Buffer], GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[Current_Buffer]); glClearColor(-1, -1, -1, -1); glClear(GL_COLOR_BUFFER_BIT); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1-Current_Buffer]); if (VP_Flood_Steplength != NULL) cgSetParameter1d(VP_Flood_Steplength, steplength); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(1.0, float(screenheight+1)); glVertex2f(float(screenwidth+1), float(screenheight+1)); glVertex2f(float(screenwidth+1), 1.0); glEnd(); glReadBuffer(fbo_attachments[Current_Buffer]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); if (steplength==1 && PassesBeforeJFA) { steplength = (screenwidth>screenheight ? screenwidth : screenheight)/2; PassesBeforeJFA = false; } else if (steplength>1) steplength /= 2; else if (SecondExit) ExitLoop = true; else { steplength = pow(2.0, (additional_passes-1)); SecondExit = true; } Current_Buffer = 1-Current_Buffer; } glReadPixels(1,1,screenwidth,screenheight,GL_RGBA,GL_FLOAT,buffer_screen); /////////////////////////////// // Test pass, Compute energy // /////////////////////////////// int Current_Energy_Buffer = 0; glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Energy_Texture[Current_Energy_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); cgGLBindProgram(VP_ComputeEnergyCentroid); cgGLBindProgram(FP_ComputeEnergyCentroid); if (FP_ComputeEnergyCentroid_Size != NULL) cgSetParameter2f(FP_ComputeEnergyCentroid_Size, screenwidth, screenheight); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, Processed_Texture[1-Current_Buffer]); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(float(screenwidth+1), 1.0); glVertex2f(float(screenwidth+1), float(screenheight+1)); glVertex2f(1.0, float(screenheight+1)); glEnd(); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); Current_Energy_Buffer = 1-Current_Energy_Buffer; ////////////////////// // perform reduction ////////////////////// cgGLBindProgram(VP_Deduction); cgGLBindProgram(FP_Deduction); bool ExitEnergyLoop = false; int quad_size = int((screenwidth>screenheight?screenwidth:screenheight)/2.0+0.5); while (!ExitEnergyLoop) { glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Energy_Texture[Current_Energy_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, Energy_Texture[1-Current_Energy_Buffer]); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(float(quad_size+1), 1.0); glVertex2f(float(quad_size+1), float(quad_size+1)); glVertex2f(1.0, float(quad_size+1)); glEnd(); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); if (quad_size>1) { int temp = quad_size/2; quad_size = temp*2==quad_size ? temp : temp+1; } else ExitEnergyLoop = true; Current_Energy_Buffer = 1-Current_Energy_Buffer; } float total_sum[4]; // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); glReadPixels(1, 1, 1, 1, GL_RGBA, GL_FLOAT, &total_sum); printf("Energy: %f\n", total_sum[0]); fEnergy = total_sum[0]; ////////////////////////////////////////// // Third pass - Scatter points to sites // ////////////////////////////////////////// cgGLBindProgram(VP_ScatterCentroid); cgGLBindProgram(FP_ScatterCentroid); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Site_Texture, 0); CheckFramebufferStatus(); glDrawBuffer(buffers[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); if (VP_ScatterCentroid_Size != NULL) cgSetParameter2f(VP_ScatterCentroid_Size, screenwidth, screenheight); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1-Current_Buffer]); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glBegin(GL_POINTS); for (i=0; i<screenwidth; i++) for (j=0; j<screenheight; j++) glVertex2f(i+1.5, j+1.5); glEnd(); glDisable(GL_BLEND); Current_Buffer = 1-Current_Buffer; /////////////////////////////////////// // Fourth pass - Test stop condition // /////////////////////////////////////// cgGLBindProgram(VP_DrawSitesOQ); cgGLBindProgram(FP_DrawSitesOQ); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[2], GL_RENDERBUFFER_EXT, RB_object); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[2]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); if (VP_DrawSitesOQ_Size != NULL) cgSetParameter2f(VP_DrawSitesOQ_Size, screenwidth, screenheight); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Site_Texture); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer]); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusion_query); glBegin(GL_POINTS); for (i=0; i<point_num; i++) { float xx, yy; xx = i%screenwidth+1.5; yy = i/screenheight+1.5; glTexCoord1f(i); glVertex2f(xx, yy); } glEnd(); glEndQueryARB(GL_SAMPLES_PASSED_ARB); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); // glReadBuffer(fbo_attachments[2]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); do{ glGetQueryObjectivARB(occlusion_query, GL_QUERY_RESULT_AVAILABLE_ARB, &oq_available); }while(oq_available); glGetQueryObjectuivARB(occlusion_query, GL_QUERY_RESULT_ARB, &sampleCount); printf("sample count: %d\n", sampleCount); cgGLDisableProfile(VertexProfile); cgGLDisableProfile(FragmentProfile); //////////////////// // compute measures //////////////////// bool *bOnBoundary = new bool[point_num]; bool *bIsHexagon = new bool[point_num]; int *nNeighbors = new int[point_num*7]; real *dDiameter = new real[point_num]; real *dNeighborDist = new real[point_num]; float site_pos[2], x, y, dist, neighbor_pos[2]; int id, drow, dcol, nrow, ncol, neighbor_id, k; real dMaxDiameter, chi_id, chi; int nHex, nVC; for (id=0; id<point_num; id++) { bOnBoundary[id] = false; bIsHexagon[id] = true; nNeighbors[id*7] = 0; for (k=1; k<7; k++) nNeighbors[id*7+k] = -1; dDiameter[id] = -1; dNeighborDist[id] = 2*(screenwidth+screenheight); } dMaxDiameter = -1; chi = -1; nHex = nVC = 0; for (i=0; i<screenheight; i++) { for (j=0; j<screenwidth; j++) { site_pos[0] = buffer_screen[i*screenwidth*4+j*4]; site_pos[1] = buffer_screen[i*screenwidth*4+j*4+1]; id = int(buffer_screen[i*screenwidth*4+j*4+2]); x = j+1.5; y = i+1.5; site_pos[0] = (site_pos[0]-1)/screenwidth*2-1; site_pos[1] = (site_pos[1]-1)/screenheight*2-1; x = (x-1)/screenwidth*2-1; y = (y-1)/screenheight*2-1; dist = (x-site_pos[0])*(x-site_pos[0])+(y-site_pos[1])*(y-site_pos[1]); dist = sqrt(dist); dDiameter[id] = dDiameter[id]<dist ? dist : dDiameter[id]; // traverse 9 neighbors for (drow=-1; drow<=1; drow++) { for (dcol=-1; dcol<=1; dcol++) { if (drow==0 && dcol==0) continue; nrow = i+drow; ncol = j+dcol; if (nrow<0 || nrow>=screenheight || ncol<0 || ncol>=screenwidth) { bOnBoundary[id] = true; continue; } neighbor_pos[0] = buffer_screen[nrow*screenwidth*4+ncol*4]; neighbor_pos[1] = buffer_screen[nrow*screenwidth*4+ncol*4+1]; neighbor_id = int(buffer_screen[nrow*screenwidth*4+ncol*4+2]); neighbor_pos[0] = (neighbor_pos[0]-1)/screenwidth*2-1; neighbor_pos[1] = (neighbor_pos[1]-1)/screenheight*2-1; if (neighbor_id==id) continue; dist = (neighbor_pos[0]-site_pos[0])*(neighbor_pos[0]-site_pos[0]) +(neighbor_pos[1]-site_pos[1])*(neighbor_pos[1]-site_pos[1]); dist = sqrt(dist); dNeighborDist[id] = dNeighborDist[id]>dist ? dist : dNeighborDist[id]; for (k=1; k<7; k++) { if (nNeighbors[id*7+k]<0) { nNeighbors[id*7+k] = neighbor_id; nNeighbors[id*7]++; break; } else if (nNeighbors[id*7+k]==neighbor_id) break; } if (k==7) bIsHexagon[id] = false; } } } } for (id=0; id<point_num; id++) { if (nNeighbors[id*7]!=6) bIsHexagon[id] = false; } for (id=0; id<point_num; id++) { dMaxDiameter = dMaxDiameter<dDiameter[id] ? dDiameter[id] : dMaxDiameter; chi_id = 2*dDiameter[id]/dNeighborDist[id]; chi = chi<chi_id ? chi_id : chi; if (!bOnBoundary[id]) { nVC++; } if (bIsHexagon[id]) { nHex++; } } printf("\n==== measures ====\n"); printf("Number of VC in the middle: %d\n", nVC); printf("Number of hexagons: %d\n", nHex); printf("h: %f\n", dMaxDiameter); printf("chi: %f\n", chi); printf("==== measures ====\n\n"); //////////////////// // Fill Octagon & another //////////////////// GLubyte *ColorTexImage = new GLubyte[screenwidth*screenheight*4]; for (i=0; i<screenheight; i++) { for (j=0; j<screenwidth; j++) { int id = i*screenwidth+j; if (id<point_num) { if (bIsHexagon[id]) { ColorTexImage[id*4] = 255; ColorTexImage[id*4+1] = 255; ColorTexImage[id*4+2] = 255; ColorTexImage[id*4+3] = 255; } else { ColorTexImage[id*4] = 192; ColorTexImage[id*4+1] = 192; ColorTexImage[id*4+2] = 192; ColorTexImage[id*4+3] = 255; } } else { ColorTexImage[id*4] = ColorTexImage[id*4+1] = ColorTexImage[id*4+2] = ColorTexImage[id*4+3] = 0.0; } } } glActiveTextureARB(GL_TEXTURE2_ARB); glGenTextures(1, &Color_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Color_Texture); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, screenwidth, screenheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, ColorTexImage); delete ColorTexImage; delete [] buffer_screen; delete [] bOnBoundary; delete [] bIsHexagon; delete [] nNeighbors; delete [] dDiameter; delete [] dNeighborDist; /////////////////////////////////// // Last pass, Display the result // /////////////////////////////////// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, screenwidth-1, 0, screenheight-1); glViewport(0, 0, screenwidth, screenheight); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer]); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Site_Texture); cgGLEnableProfile(VertexProfile); cgGLEnableProfile(FragmentProfile); cgGLBindProgram(VP_FinalRender); cgGLBindProgram(FP_FinalRender); if (FP_FinalRender_Size != NULL) cgSetParameter2f(FP_FinalRender_Size, screenwidth, screenheight); // Set parameters of fragment program glBegin(GL_QUADS); glVertex2f(0.0, 0.0); glVertex2f(0.0, float(screenheight)); glVertex2f(float(screenwidth), float(screenheight)); glVertex2f(float(screenwidth), 0.0); glEnd(); cgGLDisableProfile(VertexProfile); cgGLDisableProfile(FragmentProfile); DrawSites(xx, NULL); return fEnergy; }
void GPU::Texture2D::Unbind() const { glActiveTextureARB( m_TexUnit ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); }
int display_browser_handler(window_info *win) { //title bar //draw_menu_title_bar(browser_menu_x,browser_menu_y-16,browser_menu_x_len); // window drawing glEnable(GL_BLEND); glBlendFunc(GL_ONE,GL_SRC_ALPHA); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glColor3f(0.77f,0.57f,0.39f); glBegin(GL_LINES); //scroll bar if(!mc){ glVertex3i(win->len_x-20,20,0); glVertex3i(win->len_x-20,400,0); } if(cd!=-1){ glVertex3i(win->len_x-15,30,0); glVertex3i(win->len_x-10,25,0); glVertex3i(win->len_x-10,25,0); glVertex3i(win->len_x-5,30,0); glVertex3i(win->len_x-15,385,0); glVertex3i(win->len_x-10,390,0); glVertex3i(win->len_x-10,390,0); glVertex3i(win->len_x-5,385,0); //separators glVertex3i(0+200,0,0); glVertex3i(0+200,0+400,0); glVertex3i(0,0+200,0); glVertex3i(0+400,0+200,0); } glEnd(); glEnable(GL_TEXTURE_2D); // The X if(!mc){ draw_string(win->len_x-16,160,(unsigned char *)"B",1); draw_string(win->len_x-16,180,(unsigned char *)"A",1); draw_string(win->len_x-16,200,(unsigned char *)"C",1); draw_string(win->len_x-16,220,(unsigned char *)"K",1); } draw_string(0+win->len_x-16,0+2,(unsigned char *)"X",1); if(cd==-1){ //display dir select menu int i,x=0,y=2; if(mc==1){ for(i=0;i<=cc;i++){ draw_string(x+2,0+y,(unsigned char *)Cat[i].Name,1); y+=18; if(y>=398){ x=210; y=2; } } }else{ for(i=0;i<Cat[ccat].ns;i++){ draw_string(x+2,0+y,(unsigned char *)Cat[ccat].Sub[i]->DirName,1); y+=18; if(y>=398){ x=210; y=2; } } } }else{ // display specified dir int i=cp,valid_object=0; float tz=zoom_level; char fn[256]; // Prepare to render Leave2DMode(); glEnable(GL_CULL_FACE); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if(have_multitexture && clouds_shadows){ //bind the detail texture glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); #ifdef NEW_TEXTURES bind_texture_unbuffered(ground_detail_text); #else /* NEW_TEXTURES */ glBindTexture(GL_TEXTURE_2D, texture_cache[ground_detail_text].texture_id); #endif /* NEW_TEXTURES */ glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); } // Now we draw the 4 objects zoom_level=3.0; window_resize(); glRotatef(-60, 1.0f, 0.0f, 0.0f); glRotatef(0, 0.0f, 0.0f, 1.0f); glRotatef(45, 0.0f, 0.0f, 1.0f); glViewport(win->pos_x,window_height-win->pos_y-150,200,150); glClearStencil(0); glClear (GL_DEPTH_BUFFER_BIT); #ifdef LINUX strcpy(fn,exec_path); #else //Fedora: don't ask me why, if you use exec_path, e3d files are not found strcpy(fn,"."/*exec_path*/); #endif strcat(fn,Dir[cd].Files[i]); valid_object=setobject(0,fn,Dir[cd].xrot[i],Dir[cd].yrot[i],Dir[cd].zrot[i]); if(valid_object){ glPushMatrix(); glScalef(Dir[cd].size[i],Dir[cd].size[i],Dir[cd].size[i]); draw_3d_object(&o3d[0]); glPopMatrix(); } if(i+1<Dir[cd].nf){ glViewport(win->pos_x+200,window_height-win->pos_y-150,200,150); glClearStencil(0); glClear (GL_DEPTH_BUFFER_BIT); #ifdef LINUX strcpy(fn,exec_path); #else //Fedora: don't ask me why, if you use exec_path, e3d files are not found strcpy(fn,"."/*exec_path*/); #endif strcat(fn,Dir[cd].Files[i+1]); valid_object=setobject(1,fn,Dir[cd].xrot[i+1],Dir[cd].yrot[i+1],Dir[cd].zrot[i+1]); if(valid_object){ glPushMatrix(); glScalef(Dir[cd].size[i+1],Dir[cd].size[i+1],Dir[cd].size[i+1]); draw_3d_object(&o3d[1]); glPopMatrix(); } } if(i+2<Dir[cd].nf){ glViewport(win->pos_x,window_height-win->pos_y-350,200,150); glClearStencil(0); glClear (GL_DEPTH_BUFFER_BIT); #ifdef LINUX strcpy(fn,exec_path); #else //Fedora: don't ask me why, if you use exec_path, e3d files are not found strcpy(fn,"."/*exec_path*/); #endif strcat(fn,Dir[cd].Files[i+2]); valid_object=setobject(2,fn,Dir[cd].xrot[i+2],Dir[cd].yrot[i+2],Dir[cd].zrot[i+2]); if(valid_object){ glPushMatrix(); glScalef(Dir[cd].size[i+2],Dir[cd].size[i+2],Dir[cd].size[i+2]); draw_3d_object(&o3d[2]); glPopMatrix(); } } if(i+3<Dir[cd].nf){ glViewport(win->pos_x+200,window_height-win->pos_y-350,200,150); glClearStencil(0); glClear (GL_DEPTH_BUFFER_BIT); #ifdef LINUX strcpy(fn,exec_path); #else //Fedora: don't ask me why, if you use exec_path, e3d files are not found strcpy(fn,"."/*exec_path*/); #endif strcat(fn,Dir[cd].Files[i+3]); valid_object=setobject(3,fn,Dir[cd].xrot[i+3],Dir[cd].yrot[i+3],Dir[cd].zrot[i+3]); if(valid_object){ glPushMatrix(); glScalef(Dir[cd].size[i+3],Dir[cd].size[i+3],Dir[cd].size[i+3]); draw_3d_object(&o3d[3]); glPopMatrix(); } } zoom_level=tz; window_resize(); // Back to normal glViewport(0,0,window_width,window_height); glDisable(GL_CULL_FACE); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); if(have_multitexture && clouds_shadows) { //disable the second texture unit glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); } Enter2DMode(); CHECK_GL_ERRORS(); // Object names draw_string(win->pos_x+2,win->pos_y+200-18,(unsigned char *)Dir[cd].Names[i],1); draw_string(win->pos_x+2,win->pos_y+400-18,(unsigned char *)Dir[cd].Names[i+2],1); draw_string(win->pos_x+202,win->pos_y+200-18,(unsigned char *)Dir[cd].Names[i+1],1); draw_string(win->pos_x+202,win->pos_y+400-18,(unsigned char *)Dir[cd].Names[i+3],1); } return 1; }
void InitializeSites(int point_num) { int i, j, index; int v_per_site; VertexSiteType v; additional_passes = 0; additional_passes_before = 0; iSiteTextureHeight = point_num/screenwidth+1; bReCompute = true; // Allicate Host-Mem(site_list). for reading from Device(site_list_dev). memAllocHost<SiteType>(&site_list, &site_list_dev, point_num); // Buffer for swap site_list site_list_x = new float[(point_num) * 2]; site_list_x_bar = new float[(point_num) * 2]; site_perturb_step = 0.5f / sqrtf(point_num); if(!bReadSitesFromFile) { // ------------------------------------------------------------ // Randomize Site-position // ------------------------------------------------------------ bool *FlagArray = new bool[screenwidth*screenheight]; for (i=0; i<screenwidth*screenheight; i++) FlagArray[i] = false; for (i=0; i<point_num; i++) { SiteType s; v.x = (double)rand()/(double)RAND_MAX*(screenwidth-1.0)+1.0; v.y = (double)rand()/(double)RAND_MAX*(screenheight-1.0)+1.0; while(true) { index = int(v.y)*screenwidth+int(v.x); if (FlagArray[index]) { printf("\nDuplicate site found: #%d\n", i); v.x = v.x + ((float)rand() / (float)RAND_MAX * 2.0f - 1.0f) * (float)(screenwidth-1); v.y = v.y + ((float)rand() / (float)RAND_MAX * 2.0f - 1.0f) * (float)(screenwidth-1); while(v.x > (float)(screenwidth - 1)) { v.x -= (float)screenwidth; } while(v.x < 1.0f) { v.x += (float)screenwidth; } while(v.y > (float)(screenheight - 1)) { v.y -= (float)screenheight; } while(v.y < 1.0f) { v.y += (float)screenheight; } } else { FlagArray[index] = true; break; } } s.vertices[0] = v; s.color[0] = (float)rand()/(float)RAND_MAX; s.color[1] = (float)rand()/(float)RAND_MAX; s.color[2] = (float)rand()/(float)RAND_MAX; s.color[3] = i; site_list[i] = s; } delete FlagArray; } else { // ------------------------------------------------------------ // Read Site-position from input file. // ------------------------------------------------------------ FILE* fp = fopen("init.txt", "r"); for (i=0; i<point_num; i++) { SiteType s; fscanf(fp, "%f, %f\n", &v.x, &v.y); s.vertices[0] = v; s.color[0] = (float)rand()/(float)RAND_MAX; s.color[1] = (float)rand()/(float)RAND_MAX; s.color[2] = (float)rand()/(float)RAND_MAX; s.color[3] = i; site_list[i] = s; } fclose(fp); } // ------------------------------------------------------------ // Set Color_Texture as Site-Index // ------------------------------------------------------------ GLubyte *ColorTexImage = new GLubyte[screenwidth*screenheight*4]; for (i=0; i<screenheight; i++) for (j=0; j<screenwidth; j++) { int id = i*screenwidth+j; if (id<point_num) { ColorTexImage[id*4] = site_list[id].color[0]*255; ColorTexImage[id*4+1] = site_list[id].color[1]*255; ColorTexImage[id*4+2] = site_list[id].color[2]*255; ColorTexImage[id*4+3] = 255; } else { ColorTexImage[id*4] = ColorTexImage[id*4+1] = ColorTexImage[id*4+2] = ColorTexImage[id*4+3] = 0.0; } } glActiveTextureARB(GL_TEXTURE2_ARB); glGenTextures(1, &Color_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Color_Texture); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, screenwidth, screenheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, ColorTexImage); delete ColorTexImage; // ------------------------------------------------------------ // Create Vertext-Buffer-Oobject(VBO) & Register graphic resource for VBO // DrawSites()에서 사용. CUDA를 통해 x를 VBO에 저장하기 위해 grVBO가 필요 // ------------------------------------------------------------ glGenBuffersARB(1, &vboId); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId); glBufferDataARB(GL_ARRAY_BUFFER_ARB, point_num * sizeof(VertexSiteType), NULL, GL_DYNAMIC_DRAW_ARB); cudaGraphicsGLRegisterBuffer(&grVbo, vboId, cudaGraphicsMapFlagsWriteDiscard); // ------------------------------------------------------------ // Create Color-Buffer-Object(CBO) and set from site_list // ------------------------------------------------------------ glGenBuffersARB(1, &colorboId); glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorboId); glBufferDataARB(GL_ARRAY_BUFFER_ARB, point_num * sizeof(float) * 4, NULL, GL_DYNAMIC_DRAW_ARB); GLvoid* pointer = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); float* sitelist = (float*)pointer; for (i=0; i<point_num; i++) { sitelist[i * 4 + 0] = site_list[i].color[0]; sitelist[i * 4 + 1] = site_list[i].color[1]; sitelist[i * 4 + 2] = site_list[i].color[2]; sitelist[i * 4 + 3] = site_list[i].color[3]; } glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); }
void Draw_SV_Hitboxes(void) { if(!draw_sv_hitboxes_enable->value) return; GLint activeTextureARB = GL_TEXTURE0_ARB; GLboolean arbActive; if(g_Has_GL_ARB_multitexture) { glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTextureARB); } if(GL_TEXTURE1_ARB == activeTextureARB) { arbActive = glIsEnabled(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); } GLfloat lineWidth; GLboolean depth = glIsEnabled(GL_DEPTH_TEST); GLboolean text = glIsEnabled(GL_TEXTURE_2D); glGetFloatv(GL_LINE_WIDTH, &lineWidth); glEnable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glLineWidth(draw_sv_hitboxes_width->value); for(std::map<int, temp_edictboxes_t>::iterator it = tempEdicts.begin(); it != tempEdicts.end(); it++) { if(draw_sv_hitboxes_ignore1->value && 1 == it->first) { continue; } double red, green, blue; temp_edictboxes_t & tempEdict = it->second; if(tempEdict.isFresh) { red = hitboxesColorU[0]; green = hitboxesColorU[1]; blue = hitboxesColorU[2]; } else { red = hitboxesColor[0]; green = hitboxesColor[1]; blue = hitboxesColor[2]; } tempEdict.isFresh = false; for(std::list<temp_box_t>::iterator it2 = tempEdict.tempBoxes.begin(); it2 != tempEdict.tempBoxes.end(); it2++) { DrawBox(*it2, red, green, blue); } } glLineWidth(lineWidth); if(text) glEnable(GL_TEXTURE_2D); if(!depth) glDisable(GL_DEPTH_TEST); if(GL_TEXTURE1_ARB == activeTextureARB) { glActiveTextureARB(GL_TEXTURE1_ARB); if(arbActive) glEnable(GL_TEXTURE_2D); } }
void rglSetCombiner(rglRenderChunk_t & chunk, int format) { static char _1ma[64]; static char t1[64]; static char t1a[64]; static char t2[64]; static char t2a[64]; static char prim_lod_frac[64]; static const char *saRGB[] = { "c", t1, t2, "p/*PRIM*/", "gl_Color", "e", "1.0/*NOISE*/", "1.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0" }; static const char *mRGB[] = { "c", t1, t2, "p/*PRIM*/", "gl_Color/*SHADE*/","e", "0.0/*SCALE*/", "c.a/*COMBINED_A*/", "t1.a/*TEXEL0_A*/", "t2.a/*TEXEL1_A*/", "p.a/*PRIM_A*/", "gl_Color.a/*SHADEA*/", "e.a/*ENV_ALPHA*/", "0.5/*LOD_FRACTION*/","0.5/*PRIM_LOD_FRAC*/","k5/*K5*/", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0" }; static const char *aRGB[] = { "c", t1, t2, "p/*PRIM*/", "gl_Color/*SHADE*/","e/*ENV*/", "1.0", "0.0", }; static const char *saA[] = { "c.a", t1a, t2a, "p.a/*PRIM*/", "gl_Color.a", "e.a", "1.0", "0.0", }; static const char *sbA[] = { "c.a", t1a, t2a, "p.a/*PRIM*/", "gl_Color.a", "e.a", "1.0", "0.0", }; static const char *mA[] = { "0.5/*LOD_FRACTION*/", t1a, t2a, "p.a/*PRIM*/", "gl_Color.a/*SHADE*/", "e.a", prim_lod_frac, "0.0", }; static const char *aA[] = { "c.a", t1a, t2a, "p.a/*PRIM*/", "gl_Color.a/*SHADE*/", "e.a", "1.0", "0.0", }; const static char * bRGB[] = { "c/*PREV*/", "f", "b", "fog/*FOG*/" }; const static char * bA[2][4] = { {"c.a/*PREVA*/", "fog.a/*FOGA*/", "gl_Color.a/*SHADEA*/", "0.0/*ZERO*/"}, {_1ma/*"(1.0-c.a/ *PREVA)"*/, "0.0/*f.a*//*FRAGA*/", "1.0", "0.0"}}; // need clamping on 1-alpha ? rdpState_t & state = chunk.rdpState; static rglCombiner_t * c; uint32_t cycle = RDP_GETOM_CYCLE_TYPE(state.otherModes); int i; //, fmt, size; char * p; const char * alphaTest; const char * alphaTest2; const char * write; static char src[4*4096]; float env[4]; env[0] = RDP_GETC32_R(state.envColor)/255.0f; env[1] = RDP_GETC32_G(state.envColor)/255.0f; env[2] = RDP_GETC32_B(state.envColor)/255.0f; env[3] = RDP_GETC32_A(state.envColor)/255.0f; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env); env[0] = RDP_GETC32_R(state.blendColor)/255.0f; env[1] = RDP_GETC32_G(state.blendColor)/255.0f; env[2] = RDP_GETC32_B(state.blendColor)/255.0f; env[3] = RDP_GETC32_A(state.blendColor)/255.0f; glLightfv(GL_LIGHT0, GL_AMBIENT, env); env[0] = RDP_GETC32_R(state.fogColor)/255.0f; env[1] = RDP_GETC32_G(state.fogColor)/255.0f; env[2] = RDP_GETC32_B(state.fogColor)/255.0f; env[3] = RDP_GETC32_A(state.fogColor)/255.0f; glLightfv(GL_LIGHT0, GL_DIFFUSE, env); glActiveTextureARB(GL_TEXTURE1_ARB); env[0] = state.k5/255.0f; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env); if (cycle == RDP_CYCLE_TYPE_FILL) { if (0/*fb_size == 3*/) { // FIXME env[0] = RDP_GETC32_R(state.fillColor)/255.0f; env[1] = RDP_GETC32_G(state.fillColor)/255.0f; env[2] = RDP_GETC32_B(state.fillColor)/255.0f; env[3] = RDP_GETC32_A(state.fillColor)/255.0f; } else { env[0] = RDP_GETC16_R(state.fillColor)/31.0f; env[1] = RDP_GETC16_G(state.fillColor)/31.0f; env[2] = RDP_GETC16_B(state.fillColor)/31.0f; env[3] = RDP_GETC16_A(state.fillColor); } } else { env[0] = RDP_GETC32_R(state.primColor)/255.0f; env[1] = RDP_GETC32_G(state.primColor)/255.0f; env[2] = RDP_GETC32_B(state.primColor)/255.0f; env[3] = RDP_GETC32_A(state.primColor)/255.0f; } glLightfv(GL_LIGHT0, GL_SPECULAR, env); glActiveTextureARB(GL_TEXTURE0_ARB); rglAssert(glGetError() == GL_NO_ERROR); // if (c && rglNbCombiners && // RDP_GETOM_CYCLE_TYPE(c->otherModes) == cycle && // (RDP_GETOM_CYCLE_TYPE(c->otherModes) >= 2 || // (!memcmp(&c->combineModes, &state.combineModes, sizeof(rdpCombineModes_t)) && // !memcmp(&c->otherModes, &state.otherModes, sizeof(rdpOtherModes_t))))) { // return; // } for (i=0; i<rglNbCombiners; i++) { c = rglCombiners + i; if (c->format == format && RDP_GETOM_CYCLE_TYPE(c->otherModes) == cycle && (RDP_GETOM_CYCLE_TYPE(c->otherModes) >= 2 || (!memcmp(&c->combineModes, &state.combineModes, sizeof(rdpCombineModes_t)) && !memcmp(&c->otherModes, &state.otherModes, sizeof(rdpOtherModes_t)) ))) { #ifdef RDP_DEBUG chunk.shader = c->shader; #endif rglUseShader(c->shader); goto ok; } } if (rglNbCombiners == RGL_MAX_COMBINERS) rglClearCombiners(); c = rglCombiners + rglNbCombiners++; c->otherModes = state.otherModes; c->combineModes = state.combineModes; c->format = format; #ifndef RGL_EXACT_BLEND c->srcBlend = GL_ONE; c->dstBlend = GL_ZERO; #endif switch (format & RGL_COMB_FMT) { case RGL_COMB_FMT_RGBA: write = "gl_FragColor = c;"; break; case RGL_COMB_FMT_I: write = "gl_FragColor = vec4(c[0]);"; break; case RGL_COMB_FMT_DEPTH: write = "gl_FragDepth = c[0];"; break; } if (cycle == RDP_CYCLE_TYPE_FILL) { sprintf( src, "void main() \n" "{ \n" //" c = gl_TextureEnvColor[1];\n" " vec4 c = gl_LightSource[0].specular;\n" " %s\n" "} \n", write); c->shader = rglCreateShader( "void main() \n" "{ \n" " gl_Position = ftransform(); \n" " gl_FrontColor = gl_Color; \n" " gl_BackColor = gl_Color; \n" " gl_TexCoord[0] = gl_MultiTexCoord0; \n" "} \n" , src ); #ifdef RDP_DEBUG chunk.shader = c->shader; #endif rglUseShader(c->shader); goto ok; } alphaTest = ""; alphaTest2 = ""; if (//cycle < 2 && // CHECK THIS RDP_GETOM_CVG_TIMES_ALPHA(chunk.rdpState.otherModes) //&& rglT1Usage(chunk.rdpState) ) { if (RDP_GETOM_ALPHA_CVG_SELECT(chunk.rdpState.otherModes)) alphaTest = "if (c.a < 0.5) discard; \n"; else alphaTest = "if (t1.a < 0.5) discard; \n"; alphaTest2 = "if (c.a < 0.5) discard; \n"; } else if (RDP_GETOM_ALPHA_COMPARE_EN(chunk.rdpState.otherModes) && !RDP_GETOM_ALPHA_CVG_SELECT(chunk.rdpState.otherModes)) { if (RDP_GETC32_A(chunk.rdpState.blendColor) > 0) { alphaTest = "if (c.a < b.a) discard; \n"; alphaTest2 = " vec4 b = gl_LightSource[0].ambient; \n" " if (c.a < b.a) discard; \n"; //alphaTest2 = "if (c.a < 0.5) discard; \n"; } else { alphaTest = "if (c.a == 0.0) discard; \n"; alphaTest2 = "if (c.a == 0.0) discard; \n"; } } if (cycle == RDP_CYCLE_TYPE_COPY) { sprintf( src, "uniform sampler2D texture0; \n" " \n" "void main() \n" "{ \n" " vec4 c = texture2D(texture0, vec2(gl_TexCoord[0])); \n" " %s" " %s\n" "} \n", alphaTest2, write ); c->shader = rglCreateShader( "void main() \n" "{ \n" " gl_Position = ftransform(); \n" " gl_FrontColor = gl_Color; \n" " gl_BackColor = gl_Color; \n" " gl_TexCoord[0] = gl_MultiTexCoord0; \n" "} \n" , src ); #ifdef RDP_DEBUG chunk.shader = c->shader; #endif rglUseShader(c->shader); goto ok; } p = src; p += sprintf(p, "uniform sampler2D texture0; \n" "uniform sampler2D texture2; \n" #ifdef RGL_EXACT_BLEND "uniform sampler2D texture1; \n" #endif " \n" "void main() \n" "{ \n" "vec4 c = vec4(0,0,0,0);\n" "vec4 e = gl_TextureEnvColor[0];\n" "float k5 = gl_TextureEnvColor[1][0];\n" "vec4 p = gl_LightSource[0].specular;\n" #ifdef RGL_EXACT_BLEND "vec4 f = texture2D(texture1, vec2(gl_FragCoord.x/(2048.0*gl_TexCoord[1].x), gl_FragCoord.y/(2048.0*gl_TexCoord[1].y))); \n" #endif "vec4 fog = gl_LightSource[0].diffuse; \n" "vec4 b = gl_LightSource[0].ambient; \n"); switch (format & RGL_COMB_IN0) { case 0: p += sprintf(p, "vec4 t1 = texture2D(texture0, vec2(gl_TexCoord[0]));\n"); break; case RGL_COMB_IN0_DEPTH: p += sprintf(p, "vec4 t1 = vec4(texture2D(texture0, vec2(gl_TexCoord[0]))[0]);\n"); break; } switch (format & RGL_COMB_IN1) { case 0: p += sprintf(p, "vec4 t2 = texture2D(texture2, vec2(gl_TexCoord[2]));\n"); break; case RGL_COMB_IN1_DEPTH: p += sprintf(p, "vec4 t2 = vec4(texture2D(texture2, vec2(gl_TexCoord[2]))[0]);\n"); break; } const char * comb, * comb2; comb2 = 0; // switch (RDP_GETOM_CVG_DEST(state.otherModes)) // { // case 3: // comb = "c = clamp(vec4((vec3(%s) - vec3(%s)) * vec3(%s) + vec3(%s), (%s - %s) * %s + %s), 0.0, 1.0);\n"; // break; // case 2: // comb = "c = vec4((vec3(%s) - vec3(%s)) * vec3(%s) + vec3(%s), (%s - %s) * %s + %s);\n"; // //comb = "c = vec4((vec3(%s) - vec3(%s)) * vec3(%s) + vec3(%s), t1.a*((%s - %s) * %s + %s));\n"; // break; // case 0: // //comb2 = "c = vec4((vec3(%s) - vec3(%s)) * vec3(%s) + vec3(%s), t1.a);\n"; // case 1: // comb = "c = vec4((vec3(%s) - vec3(%s)) * vec3(%s) + vec3(%s), (%s - %s) * %s + %s);\n"; // break; // } comb = "c = clamp(vec4((vec3(%s) - vec3(%s)) * vec3(%s) + vec3(%s), (%s - %s) * %s + %s), 0.0, 1.0);\n"; strcpy(prim_lod_frac, "0.5/*PRIM_LOD_FRAC*/"); strcpy(t1, "t1"); strcpy(t1a, "t1.a"); if (format & RGL_COMB_TILE7) { strcpy(t2, "t1"); strcpy(t2a, "t1.a"); } else { strcpy(t2, "t2"); strcpy(t2a, "t2.a"); } p += sprintf(p, comb , saRGB[RDP_GETCM_SUB_A_RGB0(state.combineModes)], saRGB[RDP_GETCM_SUB_B_RGB0(state.combineModes)], mRGB[RDP_GETCM_MUL_RGB0(state.combineModes)], aRGB[RDP_GETCM_ADD_RGB0(state.combineModes)], saA[RDP_GETCM_SUB_A_A0(state.combineModes)], sbA[RDP_GETCM_SUB_B_A0(state.combineModes)], mA[RDP_GETCM_MUL_A0(state.combineModes)], aA[RDP_GETCM_ADD_A0(state.combineModes)] ); if (cycle == RDP_CYCLE_TYPE_2) { if (!(format & RGL_COMB_TILE7)) { strcpy(t1, "t2"); strcpy(t1a, "t2.a"); strcpy(t2, "t1"); strcpy(t2a, "t1.a"); } //strcpy(prim_lod_frac, "0.0/*PRIM_LOD_FRAC*/"); // if (!RDP_GETOM_ALPHA_CVG_SELECT(chunk.rdpState.otherModes)) // p += // sprintf(p, " c.a = t1.a; \n"); p += sprintf(p, comb2? comb2 : comb , saRGB[RDP_GETCM_SUB_A_RGB1(state.combineModes)], saRGB[RDP_GETCM_SUB_B_RGB1(state.combineModes)], mRGB[RDP_GETCM_MUL_RGB1(state.combineModes)], aRGB[RDP_GETCM_ADD_RGB1(state.combineModes)], saA[RDP_GETCM_SUB_A_A1(state.combineModes)], sbA[RDP_GETCM_SUB_B_A1(state.combineModes)], mA[RDP_GETCM_MUL_A1(state.combineModes)], aA[RDP_GETCM_ADD_A1(state.combineModes)] ); } // if (!RDP_GETOM_CVG_TIMES_ALPHA(state.otherModes)) // p += sprintf(p, "c.a = t1.a; \n"); p += sprintf(p, "%s", alphaTest); const char * blender; blender = "c = vec4(float(%s)*vec3(%s) + float(%s)*vec3(%s), 1.0); \n"; #ifdef RGL_EXACT_BLEND const char * noblender = "c.a = 1.0;\n"; #endif int m1b, m1a, m2b, m2a; //LOG("New combiner / blender :\n%s", rglCombiner2String(state)); if (cycle == RDP_CYCLE_TYPE_2) { if (RDP_GETOM_FORCE_BLEND(state.otherModes)) { #ifndef RGL_EXACT_BLEND if (RDP_GETOM_BLEND_M1A_0(state.otherModes) != 1 && RDP_GETOM_BLEND_M2A_0(state.otherModes) != 1) { #endif sprintf(_1ma, "(1.0 - %s)", bA[0][RDP_GETOM_BLEND_M1B_0(state.otherModes)]); p += sprintf( p, "c = vec4(float(%s)*vec3(%s) + float(%s)*vec3(%s), c.a); \n" ,bA[0][RDP_GETOM_BLEND_M1B_0(state.otherModes)], bRGB[RDP_GETOM_BLEND_M1A_0(state.otherModes)], bA[1][RDP_GETOM_BLEND_M2B_0(state.otherModes)], bRGB[RDP_GETOM_BLEND_M2A_0(state.otherModes)] ); #ifndef RGL_EXACT_BLEND } else { LOG("Blender error : fragment in cycle 1\n%s", rglCombiner2String(state)); } #endif m1b = RDP_GETOM_BLEND_M1B_1(state.otherModes); m1a = RDP_GETOM_BLEND_M1A_1(state.otherModes); m2b = RDP_GETOM_BLEND_M2B_1(state.otherModes); m2a = RDP_GETOM_BLEND_M2A_1(state.otherModes); } else { m1b = RDP_GETOM_BLEND_M1B_0(state.otherModes); m1a = RDP_GETOM_BLEND_M1A_0(state.otherModes); m2b = RDP_GETOM_BLEND_M2B_0(state.otherModes); m2a = RDP_GETOM_BLEND_M2A_0(state.otherModes); } } else { m1b = RDP_GETOM_BLEND_M1B_0(state.otherModes); m1a = RDP_GETOM_BLEND_M1A_0(state.otherModes); m2b = RDP_GETOM_BLEND_M2B_0(state.otherModes); m2a = RDP_GETOM_BLEND_M2A_0(state.otherModes); } if (RDP_GETOM_FORCE_BLEND(state.otherModes) || cycle == RDP_CYCLE_TYPE_2) { #ifndef RGL_EXACT_BLEND if (m1a == 1 || m2a == 1) { if (/*(m1a != 1 || m1b == 3) &&*/ (m2a == 1 || m2b == 3)) { int src = GL_ZERO, dst = GL_ONE; const char * alpha = "c.a"; switch (m1b) { case 0: // c.a src = GL_SRC_ALPHA; break; case 1: // fog.a src = GL_SRC_ALPHA; alpha = "fog.a"; // LOGERROR("Unsupported src alpha : FOG\n"); // LOGERROR(rglCombiner2String(state)); break; case 2: // shade.a src = GL_SRC_ALPHA; alpha = "gl_Color.a"; // LOGERROR("Unsupported src alpha : SHADE\n"); // LOGERROR(rglCombiner2String(state)); break; case 3: // 0 src = GL_ZERO; break; } switch (m1a) { case 0: // c if (m1b != 0 /* c.a */) p += sprintf( p, "c.a = %s; \n", alpha); break; case 1: // f LOGERROR("Unsupported src color : FRAG\n"); LOGERROR("%s", rglCombiner2String(state)); break; case 2: // b p += sprintf( p, "c = vec4(vec3(b), %s); \n", alpha); break; case 3: // fog p += sprintf( p, "c = vec4(vec3(fog), %s); \n", alpha); break; } switch (m2b) { case 0: switch (m1b) { case 3: dst = GL_ONE; break; default: dst = GL_ONE_MINUS_SRC_ALPHA; break; } break; case 1: dst = GL_DST_ALPHA; break; case 2: dst = GL_ONE; break; case 3: dst = GL_ZERO; break; } c->srcBlend = src; c->dstBlend = dst; } else { LOGERROR("Unsuported blender :\n"); LOGERROR("%s", rglCombiner2String(state)); } } else #endif { sprintf(_1ma, "(1.0 - %s)", bA[0][m1b]); p += sprintf(p, blender, bA[0][m1b], bRGB[m1a], bA[1][m2b], bRGB[m2a]); } } else { #ifdef RGL_EXACT_BLEND p += sprintf(p, noblender ); #endif } p += sprintf( p, "%s \n" "} \n" ,write ); rglAssert(p < src+sizeof(src)); c->shader = rglCreateShader( "void main() \n" "{ \n" " gl_Position = ftransform(); \n" " gl_FrontColor = gl_Color; \n" " gl_BackColor = gl_FrontColor; \n" " gl_TexCoord[0] = gl_MultiTexCoord0; \n" #ifdef RGL_EXACT_BLEND " gl_TexCoord[1] = gl_MultiTexCoord1; \n" #endif " gl_TexCoord[2] = gl_MultiTexCoord2; \n" "} \n" , src); #ifdef RDP_DEBUG chunk.shader = c->shader; #endif rglUseShader(c->shader); rglAssert(glGetError() == GL_NO_ERROR); int location; location = glGetUniformLocationARB(c->shader->prog, "texture0"); glUniform1iARB(location, 0); #ifdef RGL_EXACT_BLEND location = glGetUniformLocationARB(c->shader->prog, "texture1"); glUniform1iARB(location, 1); #endif location = glGetUniformLocationARB(c->shader->prog, "texture2"); glUniform1iARB(location, 2); rglAssert(glGetError() == GL_NO_ERROR); ok:; #ifndef RGL_EXACT_BLEND if ((format & RGL_COMB_FMT) == RGL_COMB_FMT_DEPTH || (c->srcBlend == GL_ONE && c->dstBlend == GL_ZERO)) glDisable(GL_BLEND); else { glEnable(GL_BLEND); if ((format & RGL_COMB_FMT) == RGL_COMB_FMT_RGBA) glBlendFuncSeparate(c->srcBlend, c->dstBlend, GL_ZERO, GL_ONE); else glBlendFunc(c->srcBlend, c->dstBlend); } #endif }
//-------------------------------------------------------------- // Name: CBRUTE_FORCE::Render - public // Description: Render the terrain height field // Arguments: None // Return Value: None //-------------------------------------------------------------- void CBRUTE_FORCE::Render( void ) { float fTexLeft, fTexBottom, fTexTop; int x, z; //reset the counting variables m_iVertsPerFrame= 0; m_iTrisPerFrame = 0; //cull non camera-facing polygons glEnable( GL_CULL_FACE ); if( m_bMultitexture && m_bDetailMapping && m_bTextureMapping ) { glDisable( GL_BLEND ); //bind the primary color texture to the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texture.GetID( ) ); //bind the detail color texture to the second texture unit glActiveTextureARB( GL_TEXTURE1_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_detailMap.GetID( ) ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB ); glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2 ); //loop through the Z-axis of the terrain for( z=0; z<m_iSize-1; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x=0; x<m_iSize-1; x++ ) { //calculate the texture coordinates fTexLeft = ( float )x/m_iSize; fTexBottom= ( float )z/m_iSize; fTexTop = ( float )( z+1 )/m_iSize; //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexBottom ); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, fTexLeft*m_iRepeatDetailMap, fTexBottom*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z ), ( float )z ); //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexTop ); glMultiTexCoord2fARB( GL_TEXTURE1_ARB, fTexLeft*m_iRepeatDetailMap, fTexTop*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z+1 ), ( float )z+1 ); //increase the vertex count by two (which is how many we sent to the API) m_iVertsPerFrame+= 2; //there are no triangles being rendered on the first X-loop, they just start the //triangle strip off if( x!= 0 ) m_iTrisPerFrame+= 2; } //end the triangle strip glEnd( ); } //unbind the texture occupying the second texture unit glActiveTextureARB( GL_TEXTURE1_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); //unbind the texture occupying the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); } //multitexturing is not enabled, which means we'll have to do a seperate texture //pass if detail mapping is needed else { if( m_bTextureMapping ) { //bind the primary color texture (FOR THE PRIMARY TEXTURE PASS) glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texture.GetID( ) ); //loop through the Z-axis of the terrain for( z=0; z<m_iSize-1; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x=0; x<m_iSize-1; x++ ) { //calculate the texture coordinates fTexLeft = ( float )x/m_iSize; fTexBottom= ( float )z/m_iSize; fTexTop = ( float )( z+1 )/m_iSize; //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexBottom ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z ), ( float )z ); //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft, fTexTop ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z+1 ), ( float )z+1 ); //increase the vertex count by two (which is how many we sent to the API) m_iVertsPerFrame+= 2; //there are no triangles being rendered on the first X-loop, they just start the //triangle strip off if( x!= 0 ) m_iTrisPerFrame+= 2; } //end the triangle strip glEnd( ); } } //if the user wants detail mapping, we need to set some things up if( m_bDetailMapping ) { //bind the detail texture glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_detailMap.GetID( ) ); //only use blending if a texture pass was made if( m_bTextureMapping ) { glEnable( GL_BLEND ); glBlendFunc( GL_ZERO, GL_SRC_COLOR ); } } //if there is no detail mapping, but a texture pass was made //then we don't need to continue else if( m_bTextureMapping ) return; //the user didn't want detail texturing nor color texturing, //but we still need to render the terrain else { //unbind the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); } //loop through the Z-axis of the terrain for( z=0; z<m_iSize-1; z++ ) { //begin a new triangle strip glBegin( GL_TRIANGLE_STRIP ); //loop through the X-axis of the terrain //this is where the triangle strip is constructed for( x=0; x<m_iSize-1; x++ ) { //calculate the texture coordinates fTexLeft = ( float )x/m_iSize; fTexBottom= ( float )z/m_iSize; fTexTop = ( float )( z+1 )/m_iSize; //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft*m_iRepeatDetailMap, fTexBottom*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z ), ( float )z ); //set the color with OpenGL, and render the point glColor3ub( 255, 255, 255 ); glMultiTexCoord2fARB( GL_TEXTURE0_ARB, fTexLeft*m_iRepeatDetailMap, fTexTop*m_iRepeatDetailMap ); glVertex3f( ( float )x, GetScaledHeightAtPoint( x, z+1 ), ( float )z+1 ); //increase the vertex count by two (which is how many we sent to the API) m_iVertsPerFrame+= 2; //there are no triangles being rendered on the first X-loop, they just start the //triangle strip off if( x!= 0 ) m_iTrisPerFrame+= 2; } //end the triangle strip glEnd( ); } glDisable( GL_BLEND ); } }
void CSM3GroundDrawer::Draw(const DrawPass::e& drawPass) { if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } terrain::RenderContext* currc = rc; tr->SetShaderParams(sky->GetLight()->GetLightDir(), currc->cam->pos); if (shadowHandler->shadowsLoaded) { terrain::ShadowMapParams params; params.mid[0] = shadowHandler->GetShadowParams().x; params.mid[1] = shadowHandler->GetShadowParams().y; params.f_a = shadowHandler->GetShadowParams().z; params.f_b = shadowHandler->GetShadowParams().w; params.shadowMap = shadowHandler->shadowTexture; for (int a = 0; a < 16; a++) params.shadowMatrix[a] = shadowHandler->shadowMatrix[a]; tr->SetShadowParams(¶ms); } tr->SetActiveContext(currc); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, sky->GetLight()->GetLightDir()); float d[4] = {0.0f, 0.0f, 0.0f, 1.0f}; const float z[] = {0.0f, 0.0f, 0.0f, 1.0f}; for (int a = 0; a < 3; a++) d[a] = mapInfo->light.groundSunColor[a]; glLightfv(GL_LIGHT0, GL_DIFFUSE, d); for (int a = 0; a < 3; a++) d[a] = mapInfo->light.groundAmbientColor[a]; glLightfv(GL_LIGHT0, GL_AMBIENT, d); for (int a = 0; a < 3; a++) d[a] = mapInfo->light.groundSpecularColor[a]; glLightfv(GL_LIGHT0, GL_SPECULAR, d); for (int a = 0; a < 4; a++) d[a] = 0.0f; glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, d); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, z); glDisable(GL_LIGHT1); glEnable(GL_LIGHT0); glEnable(GL_RESCALE_NORMAL); // glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,dir.getf()); // glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90.0f); /* const float ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f }; const float diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); const float md[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, md); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, md); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);*/ ///////////////////// tr->Draw(); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } if (drawMode != drawNormal) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.0f, -10.0f); glColor4f(1.0f, 1.0f, 1.0f, 0.5f); tr->DrawOverlayTexture(infoTex); glDisable(GL_POLYGON_OFFSET_FILL); glDepthMask(GL_TRUE); glDisable(GL_BLEND); } glFrontFace(GL_CCW); glDisable(GL_CULL_FACE); glColor3ub(255, 255, 255); DrawObjects(drawPass); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }
//-------------------------------------------------------------- void testApp::draw(){ if(fboUsed) { // set the rendering destination to FBO glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId); nmShader.setShaderActive(true); glViewport(0, 0, ofGetWidth(), ofGetHeight()); glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); camera->setView(); drawCity(); glPopMatrix(); nmShader.setShaderActive(false); #ifdef DEBUG // glReadPixels(0,0,ofGetWidth(),ofGetHeight(),GL_COLOR_ATTACHMENT0_EXT,GL_RGB8, colourBytes); // colourImage.saveImage("ColourBuffer.png"); // glReadPixels(0,0,ofGetWidth(),ofGetHeight(),GL_DEPTH_ATTACHMENT_EXT,GL_UNSIGNED_BYTE, depthBytes); // depthImage.saveImage("DepthBuffer.png"); #endif // Switch to Final Render Buffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboIdFinal); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // trigger mipmaps generation explicitly // NOTE: If GL_GENERATE_MIPMAP is set to GL_TRUE, then glCopyTexSubImage2D() // triggers mipmap generation automatically. However, the texture attached // onto a FBO should generate mipmaps manually via glGenerateMipmapEXT(). // back to normal viewport and projection matrix glViewport(0, 0, ofGetWidth(), ofGetHeight()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-ofGetWidth()/2,ofGetWidth()/2,-ofGetHeight()/2,ofGetHeight()/2,1,20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_TEXTURE_2D); ssao2Shader.setShaderActive(true); glActiveTextureARB(GL_TEXTURE0_ARB); glGenerateMipmapEXT(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,colourTextureId); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D,noiseTextureId); // This is needed and fails without but I suspect is a slow down bottleneck! ssao2Shader.setUniformVariable1i("normalMap",0); ssao2Shader.setUniformVariable1i("rnm",1); ssao2Shader.setUniformVariable1f("totStrength", totStrength); ssao2Shader.setUniformVariable1f("strength", ssaoStrength); ssao2Shader.setUniformVariable1f("offset", ssaoOffset); ssao2Shader.setUniformVariable1f("falloff",ssaoFalloff ); ssao2Shader.setUniformVariable1f("rad", ssaoRad); glScalef(0.25, 0.25, 0.25); glTranslated(0,0,-2); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glMultiTexCoord2f(GL_TEXTURE0_ARB, 0, 0); glMultiTexCoord2f(GL_TEXTURE1_ARB, 0, 0); glVertex3f(-ofGetWidth()/2,-ofGetHeight()/2,0); glMultiTexCoord2f(GL_TEXTURE0_ARB, 1, 0); glMultiTexCoord2f(GL_TEXTURE1_ARB, 1, 0); glVertex3f(ofGetWidth()/2,-ofGetHeight()/2,0); glMultiTexCoord2f(GL_TEXTURE0_ARB, 1, 1); glMultiTexCoord2f(GL_TEXTURE1_ARB, 1, 1); glVertex3f(ofGetWidth()/2,ofGetHeight()/2,0); glMultiTexCoord2f(GL_TEXTURE0_ARB, 0, 1); glMultiTexCoord2f(GL_TEXTURE1_ARB, 0, 1); glVertex3f(-ofGetWidth()/2,ofGetHeight()/2,0); glEnd(); ssao2Shader.setShaderActive(false); // back to normal window-system-provided framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // unbind glViewport(0, 0, ofGetWidth(), ofGetHeight()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-ofGetWidth()/2,ofGetWidth()/2,-ofGetHeight()/2,ofGetHeight()/2,1,20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (blurStep){ blurShader.setShaderActive(true); blurShader.setUniformVariable2f("ScaleU",1.0/ofGetWidth(),1.0/ofGetHeight()); blurShader.setUniformVariable1i("textureSource",2); } glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_2D,finalTextureId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glPushMatrix(); glTranslated(0,0,-5); glColor3f(0.95, 0.97, 1.0); glBegin(GL_QUADS); glMultiTexCoord2f(GL_TEXTURE2_ARB, 0, 0);glVertex3f(-ofGetWidth()/2,-ofGetHeight()/2,0); glMultiTexCoord2f(GL_TEXTURE2_ARB, 1, 0);glVertex3f(ofGetWidth()/2,-ofGetHeight()/2,0); glMultiTexCoord2f(GL_TEXTURE2_ARB, 1, 1);glVertex3f(ofGetWidth()/2,ofGetHeight()/2,0); glMultiTexCoord2f(GL_TEXTURE2_ARB, 0, 1);glVertex3f(-ofGetWidth()/2,ofGetHeight()/2,0); glEnd(); glPopMatrix(); if(blurStep) blurShader.setShaderActive(false); glDisable(GL_TEXTURE_2D); glPushMatrix(); glTranslated(-ofGetWidth() /2,ofGetHeight() /2,-2); glRotatef(180, 1.0, 0, 0); if (showGui) gui.draw(); glPopMatrix(); } else { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-ofGetWidth()/2,ofGetWidth()/2,-ofGetHeight()/2,ofGetHeight()/2,1,20); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslated(0,0,-1500); glColor3f(1.0, 0.0, 0.0); glBegin(GL_QUADS); glVertex3f(-ofGetWidth()/2,-ofGetHeight()/2,0); glVertex3f(ofGetWidth()/2,-ofGetHeight()/2,0); glVertex3f(ofGetWidth()/2,ofGetHeight()/2,0); glVertex3f(-ofGetWidth()/2,ofGetHeight()/2,0); glEnd(); glPopMatrix(); } // Flick back to standard projection and draw our QUAD }
void drawObjects(void) { int x, y; float float_x, float_y, float_xb, float_yb; glTranslatef(transZ, 0.0, -transX); glRotatef(xrot, 0.0, 1.0, 0.0); //glRotatef(-yrot, 0.0, 1.0, 0.0); // Ground //glColor4f(0.3f,0.3f,0.3f,1); //glEnable( GL_TEXTURE_2D ); //glBindTexture( GL_TEXTURE_2D, tex ); glBegin(GL_QUADS); //glTexCoord2f(0, 0); glColor4f(0.54f,0.27f,0.07f,1); glVertex3f(-35,-5,-35); //glTexCoord2f(1, 0); glColor4f(0.54f,0.27f,0.07f,1); glVertex3f(-35,-5, 15); //glTexCoord2f(1, 1); glColor4f(0.54f,0.27f,0.07f,1); glVertex3f( 15,-5, 15); //glTexCoord2f(0, 1); glColor4f(0.54f,0.27f,0.07f,1); glVertex3f( 15,-5,-35); //glTexCoord2f(0, 0); glColor4f(0.5f,0.5f,0.0f,1); glVertex3f(-35,12,-35); //glTexCoord2f(1, 0); glColor4f(0.5f,0.5f,0.0f,1); glVertex3f(-35,12, 15); glColor4f(0.5f,0.5f,0.0f,1); //glTexCoord2f(1, 1); glColor4f(0.5f,0.5f,0.0f,1); glVertex3f( -35,-5, 15); //glTexCoord2f(0, 1); glColor4f(0.5f,0.5f,0.0f,1); glVertex3f( -35,-5,-35); glEnd(); glPushMatrix(); glTranslatef(0,-2.5,-16); glColor4f(0.9f,0.9f,0.9f,1); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(0,-2.5,-16); glutSolidCube(4); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPushMatrix(); glUseProgram(shaderProgram); setLighting(); setMaterial(); glTranslatef(-20,-2.5,-20); glRotatef(-90, 1.0, 0.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(-20,-2.5,-20); glutSolidCube(4); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); //endTranslate(); glUseProgram(0); glPushMatrix(); glUseProgram(shaderProgram); setLighting(); setMaterial(); glTranslatef(0,0,-5); glRotatef(-90, 1.0, 0.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(0,0,-5); glutSolidSphere(2,25,25); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); //endTranslate(); glUseProgram(0); glPushMatrix(); glUseProgram(shaderProgram); setLighting(); setMaterial(); glTranslatef(-20,7,-10); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(-20,7,-10); glBegin(GL_QUADS); for( x = 0; x < 44; x++ ) { for( y = 0; y < 44; y++ ) { float_x = float(x)/44.0f; float_y = float(y)/44.0f; float_xb = float(x+1)/44.0f; float_yb = float(y+1)/44.0f; //glTexCoord2f( float_x, float_y); //glColor4f(1.0, 0.0, 0.0, 1.0); glVertex3f( points[x][y][0], points[x][y][1], points[x][y][2] ); // glTexCoord2f( float_x, float_yb ); //glColor4f(0.0, 1.0, 0.0, 1.0); glVertex3f( points[x][y+1][0], points[x][y+1][1], points[x][y+1][2] ); // glTexCoord2f( float_xb, float_yb ); //glColor4f(0.0, 0.0, 1.0, 1.0); glVertex3f( points[x+1][y+1][0], points[x+1][y+1][1], points[x+1][y+1][2] ); // glTexCoord2f( float_xb, float_y ); //glColor4f(1.0, 1.0, 0.0, 1.0); glVertex3f( points[x+1][y][0], points[x+1][y][1], points[x+1][y][2] ); } } glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); if( wiggle_count == 2 ) { for( y = 0; y < 45; y++ ) { hold=points[0][y][2]; for( x = 0; x < 44; x++) { points[x][y][2] = points[x+1][y][2]; } points[44][y][2]=hold; } wiggle_count = 0; } wiggle_count++; // Instead of calling glTranslatef, we need a custom function that also maintain the light matrix //startTranslate(0,10,-16); glUseProgram(0); glPushMatrix(); glUseProgram(shaderProgram); setMaterial2(); setLighting2(); glTranslatef(-15.5,-5,-10); glRotatef(-90, 1.0, 0.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(-15.5,-5,-10); GLUquadric *quadratic = gluNewQuadric(); gluCylinder(quadratic, 0.75f, 0.75f, 17.0f, 10.0f, 10.0f); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glUseProgram(0); glPushMatrix(); glUseProgram(shaderProgram); setMaterial3(); setLighting3(); glTranslatef(-15.5,12,-10); glRotatef(-90, 1.0, 0.0, 0.0); glRotatef(90, 0.0, 0.0, 1.0); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(-15.5,12,-10); glutSolidSphere(1,25,25); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glUseProgram(0); glPushMatrix(); glUseProgram(toonProgram); setMaterial3(); setLighting3(); glTranslatef(-10,-2.5,-30); //glRotatef(-90, 1.0, 0.0, 0.0); //glRotatef(90, 0.0, 0.0, 1.0); glMatrixMode(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE7); glPushMatrix(); glTranslatef(-10,-5,-30); glutSolidTorus(1.5, 2.0, 10.0, 50.0); //glutSolidTeapot(4); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glUseProgram(0); }
void DriftingGratingStimulus::drawFrame(shared_ptr<StimulusDisplay> display) { glPushMatrix(); glTranslatef(xoffset->getValue().getFloat(), yoffset->getValue().getFloat(), 0); glRotatef(rotation->getValue().getFloat(),0,0,1); GLfloat scale_size = MAX(width->getValue().getFloat(), height->getValue().getFloat()); glScalef(scale_size, scale_size, 1.0); // scale it up // ---------------------------------------- // GRATING // ---------------------------------------- glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); // Associate with texture 0 glEnable(GL_TEXTURE_1D); // select our current texture glBindTexture( GL_TEXTURE_1D, grating_textures[display->getCurrentContextIndex()] ); // select modulate to mix texture with color for shading glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); // when texture area is small, bilinear filter the closest mipmap glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); // when texture area is large, bilinear filter the first mipmap glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // if wrap is true, the texture wraps over at the edges (repeat) // ... false, the texture ends at the edges (clamp) glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glEnable(GL_TEXTURE_1D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,1); // ---------------------------------------- // MASK // ---------------------------------------- glActiveTextureARB(GL_TEXTURE1_ARB); // associate with TEXTURE1_ARB glEnable(GL_TEXTURE_2D); // select our current texture glBindTexture( GL_TEXTURE_2D, mask_textures[display->getCurrentContextIndex()] ); // select modulate to mix texture with color for shading glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); // ---------------------------------------- // DRAW THE QUAD // ---------------------------------------- glBegin(GL_QUADS); MWTime elapsed_time = getElapsedTime(); // here's the description of this equation // starting_phase is in degrees -> degrees*pi/180 = radians // // speed is in degrees/second // spatial_frequency is in cycles/degree // elapsed_time is time since the start the 'play' in us // us/100000 = seconds // // degrees cycles 1 second pi radians // ------- * ------ * ---------- * ----------- * us = radians of phase // s degree 1000000 us 180 degrees // // multiply by -1 so it the grating goes in the correct direction double elapsed_seconds = (double)elapsed_time / (double)1000000; const double phase = -1*(starting_phase->getValue().getFloat()*(M_PI/180.) + speed->getValue().getFloat()*spatial_frequency->getValue().getFloat()*(2.*M_PI)*elapsed_seconds); const double direction_in_radians = direction_in_degrees->getValue().getFloat()*(M_PI/180.); const double aspect = width->getValue().getFloat()/height->getValue().getFloat(); //mprintf("drifting grating draw (%lld - %lld = %lld, %g, %g, %g, %g)", now, start_time, elapsed_time, elapsed_seconds, phase, direction_in_radians, aspect); const float f = cos(direction_in_radians); const float g = sin(direction_in_radians); const float d = ((f+g)-1)/2; const float texture_bl = 0-d; const float texture_br = texture_bl+f; const float texture_tr = 1+d; const float texture_tl = texture_bl+g; const float mask_s_ratio = 1-MIN(1,aspect); const float mask_t_ratio = 1-MIN(1,1/aspect); const float phase_proportion = phase/(2*M_PI); const float cycle_proportion = spatial_frequency->getValue().getFloat()*width->getValue().getFloat(); glNormal3f(0.0, 0.0, 1.0); glMultiTexCoord1fARB(GL_TEXTURE0_ARB, (cycle_proportion*texture_bl)+phase_proportion); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0-mask_s_ratio, 0-mask_t_ratio); glVertex3f(-0.5,-0.5,0); glMultiTexCoord1fARB(GL_TEXTURE0_ARB, (cycle_proportion*texture_br)+phase_proportion); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1+mask_s_ratio, 0-mask_t_ratio); glVertex3f(0.5,-0.5,0); glMultiTexCoord1fARB(GL_TEXTURE0_ARB, (cycle_proportion*texture_tr)+phase_proportion); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1+mask_s_ratio, 1+mask_t_ratio); glVertex3f(0.5,0.5,0); glMultiTexCoord1fARB(GL_TEXTURE0_ARB, (cycle_proportion*texture_tl)+phase_proportion); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0-mask_s_ratio, 1+mask_t_ratio); glVertex3f(-0.5,0.5,0); glEnd(); // GL_QUADS last_phase = phase*(180/M_PI); // ---------------------------------------- // CLEAN-UP // ---------------------------------------- // Unbind grating texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture( GL_TEXTURE_1D, 0 ); glDisable(GL_TEXTURE_1D); // Unbind mask texture glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture( GL_TEXTURE_2D, 0 ); glDisable(GL_TEXTURE_2D); glActiveTextureARB(0); // // If alpha_multiplier is less than 1, draw another polygon on top to reduce contrast // float tB = alpha_multiplier->getValue().getFloat(); if ((tB < 1.0f) && (tB >= 0.0f)) { glBegin(GL_QUADS); glColor4f(0.5,0.5,0.5,1-tB); // MH 100730 I believe all grating types have mean 0.5 hardcoded now, fade to 0.5 glVertex3f(-0.5,-0.5,0); glVertex3f(0.5,-0.5,0); glVertex3f(0.5,0.5,0); glVertex3f(-0.5,0.5,0); glEnd(); // GL_QUADS } glPopMatrix(); }
void DriftingGratingStimulus::load(shared_ptr<StimulusDisplay> display) { if (loaded) return; for(int i = 0; i < display->getNContexts(); ++i) { display->setCurrent(i); GLuint textures[2]; glGenTextures(2, textures); mask_textures.push_back(textures[0]); grating_textures.push_back(textures[1]); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_1D); // ---------------------------------------- // GRATING // ---------------------------------------- // select our current texture glBindTexture( GL_TEXTURE_1D, grating_textures[i] ); // select modulate to mix texture with color for shading glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); // when texture area is small, bilinear filter the closest mipmap glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); // when texture area is large, bilinear filter the first mipmap glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // if wrap is true, the texture wraps over at the edges (repeat) // ... false, the texture ends at the edges (clamp) glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT ); gluBuild1DMipmaps(GL_TEXTURE_1D, GL_LUMINANCE, grating->getDataSize(), GL_LUMINANCE, GL_FLOAT, grating->get1DData()); glEnable(GL_TEXTURE_1D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,1); // ---------------------------------------- // MASK // ---------------------------------------- glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); // select our current texture glBindTexture( GL_TEXTURE_2D, mask_textures[i] ); // select modulate to mix texture with color for shading glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); gluBuild2DMipmaps(GL_TEXTURE_2D, 2, mask->getSize(), mask->getSize(), GL_LUMINANCE_ALPHA, GL_FLOAT, mask->get2DData()); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); // Unbind grating texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture( GL_TEXTURE_1D, 0 ); glBindTexture( GL_TEXTURE_2D, 0 ); glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); // Unbind mask texture glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture( GL_TEXTURE_1D, 0 ); glBindTexture( GL_TEXTURE_2D, 0 ); glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); glActiveTextureARB(0); } loaded = true; }
int main(int argc, char* argv[]) { char* b3dFilePath; /* camera variables */ float angleX = 0.f, angleY = 0.f; float positionX = 0.f, positionY = 0.f, positionZ = 0.f; /* camera movement variables */ float forwardX = 0.f, forwardY = 0.f, forwardZ = 1.f; float rightX = 1.f, rightY = 0.f, rightZ = 0.f; /* memory to store only the rotation transform of the view matrix */ float viewRotation[16]; if (argc < 2) b3dFilePath = "test1/test1.b3d"; else b3dFilePath = argv[1]; b3dTest = loadB3DFile(b3dFilePath); /* printf("textures:\n"); printf("directory: %s\n", getDirectoryFromFile(b3dTest)); printf("texture count: %d\n", getNumberOfTexturesFromBRUSChunk(getBRUSChunkFromBB3DChunk(getBB3DChunkFromFile(b3dTest)))); */ SDL_Init(SDL_INIT_VIDEO); glWindow = SDL_CreateWindow("B3D Lightmap Viewer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL); glContext = SDL_GL_CreateContext(glWindow); glActiveTextureARB = SDL_GL_GetProcAddress("glActiveTextureARB"); glClientActiveTextureARB = SDL_GL_GetProcAddress("glClientActiveTextureARB"); keyPress = SDL_GetKeyboardState(NULL); /* multitexture setup */ /* commentary: possible support for more than 2 texture layers? if necessary. */ textures = loadTextures(b3dTest); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); /* OpenGL initial setup */ glClearColor(0.f, 0.f, 0.5f, 1.f); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); gluPerspective(70.0, 1.333, 10, 10000); glMatrixMode(GL_MODELVIEW); /* main loop */ while (!quit) { int differentialX = 0, differentialY = 0; int mouseStates = 0; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) quit = 1; } if (keyPress[SDL_SCANCODE_ESCAPE]) quit = 1; mouseStates = SDL_GetRelativeMouseState(&differentialX, &differentialY); /* change camera orientation when mouse dragged */ if (mouseStates & SDL_BUTTON(SDL_BUTTON_LEFT)) { angleX -= MOUSE_VERTICAL_SENSITIVITY * differentialY; angleY -= MOUSE_HORIZONTAL_SENSITIVITY * differentialX; } /* use existing base vectors in view rotation matrix for movement */ forwardX = viewRotation[2]; forwardY = viewRotation[6]; forwardZ = viewRotation[10]; rightX = viewRotation[0]; rightY = viewRotation[4]; rightZ = viewRotation[8]; /* move camera forward when W pressed */ if (keyPress[SDL_SCANCODE_W]) { positionX -= CAMERA_SPEED * forwardX; positionY -= CAMERA_SPEED * forwardY; positionZ -= CAMERA_SPEED * forwardZ; } /* move camera left when A pressed */ if (keyPress[SDL_SCANCODE_A]) { positionX -= CAMERA_SPEED * rightX; positionY -= CAMERA_SPEED * rightY; positionZ -= CAMERA_SPEED * rightZ; } /* move camera backward when S pressed */ if (keyPress[SDL_SCANCODE_S]) { positionX += CAMERA_SPEED * forwardX; positionY += CAMERA_SPEED * forwardY; positionZ += CAMERA_SPEED * forwardZ; } /* move camera right when D pressed */ if (keyPress[SDL_SCANCODE_D]) { positionX += CAMERA_SPEED * rightX; positionY += CAMERA_SPEED * rightY; positionZ += CAMERA_SPEED * rightZ; } /* reset camera position and orientation when R pressed */ if (keyPress[SDL_SCANCODE_R]) { positionX = 0.f; positionY = 0.f; positionZ = 0.f; angleX = 0.f; angleY = 0.f; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* construct the view matrix */ glLoadIdentity(); glRotatef(-angleX, 1.f, 0.f, 0.f); glRotatef(-angleY, 0.f, 1.f, 0.f); glGetFloatv(GL_MODELVIEW_MATRIX, viewRotation); glTranslatef(-positionX, -positionY, -positionZ); glScalef(1.f, 1.f, -1.f); drawB3D(b3dTest); SDL_GL_SwapWindow(glWindow); SDL_Delay(16); } /* commentary: still need to clear the loaded data from memory */ SDL_DestroyWindow(glWindow); SDL_Quit(); return 0; }
bool Sample_22::doMesh2TexelUnits() { GLfloat c[4]={0.0f,0.0f,0.0f,1.0f}; // holds current vertex GLfloat n[4]={0.0f,0.0f,0.0f,1.0f}; // normalized normal of current surface GLfloat s[4]={0.0f,0.0f,0.0f,1.0f}; // s-texture coordinate direction, normalized GLfloat t[4]={0.0f,0.0f,0.0f,1.0f}; // t-texture coordinate direction, normalized GLfloat l[4]; // holds our lightposition to be transformed into object space GLfloat Minv[16]; // holds the inverted modelview matrix to do so. int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer // Build Inverse Modelview Matrix First. This Substitutes One Push/Pop With One glLoadIdentity(); // Simply Build It By Doing All Transformations Negated And In Reverse Order. glLoadIdentity(); glRotatef(-m_yrot,0.0f,1.0f,0.0f); glRotatef(-m_xrot,1.0f,0.0f,0.0f); glTranslatef(0.0f,0.0f,-m_z); glGetFloatv(GL_MODELVIEW_MATRIX,Minv); glLoadIdentity(); glTranslatef(0.0f,0.0f,m_z); glRotatef(m_xrot,1.0f,0.0f,0.0f); glRotatef(m_yrot,0.0f,1.0f,0.0f); // Transform The Lightposition Into Object Coordinates: l[0]=s_LightPosition[0]; l[1]=s_LightPosition[1]; l[2]=s_LightPosition[2]; l[3]=1.0f; // Homogenous Coordinate VMatMult(Minv,l); /* PASS#1: Texel-Unit 0: Use Texture "Bump" No Blend No Lighting No Offset Texture-Coordinates Texture-Operation "Replace" Texel-Unit 1: Use Texture "Invbump" No Lighting Offset Texture Coordinates Texture-Operation "Replace" */ // TEXTURE-UNIT #0 glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_bump[m_filter]); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE); // TEXTURE-UNIT #1: glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_invbump[m_filter]); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD); // General Switches: glDisable(GL_BLEND); glDisable(GL_LIGHTING); glBegin(GL_QUADS); // Front Face n[0]=0.0f; n[1]=0.0f; n[2]=1.0f; s[0]=1.0f; s[1]=0.0f; s[2]=0.0f; t[0]=0.0f; t[1]=1.0f; t[2]=0.0f; for (i=0; i<4; i++) { c[0]=s_data[5*i+2]; c[1]=s_data[5*i+3]; c[2]=s_data[5*i+4]; SetUpBumps(n,c,l,s,t); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,s_data[5*i] , s_data[5*i+1]); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s_data[5*i]+c[0], s_data[5*i+1]+c[1]); glVertex3f(s_data[5*i+2], s_data[5*i+3], s_data[5*i+4]); } // Back Face n[0]=0.0f; n[1]=0.0f; n[2]=-1.0f; s[0]=-1.0f; s[1]=0.0f; s[2]=0.0f; t[0]=0.0f; t[1]=1.0f; t[2]=0.0f; for (i=4; i<8; i++) { c[0]=s_data[5*i+2]; c[1]=s_data[5*i+3]; c[2]=s_data[5*i+4]; SetUpBumps(n,c,l,s,t); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,s_data[5*i] , s_data[5*i+1]); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s_data[5*i]+c[0], s_data[5*i+1]+c[1]); glVertex3f(s_data[5*i+2], s_data[5*i+3], s_data[5*i+4]); } // Top Face n[0]=0.0f; n[1]=1.0f; n[2]=0.0f; s[0]=1.0f; s[1]=0.0f; s[2]=0.0f; t[0]=0.0f; t[1]=0.0f; t[2]=-1.0f; for (i=8; i<12; i++) { c[0]=s_data[5*i+2]; c[1]=s_data[5*i+3]; c[2]=s_data[5*i+4]; SetUpBumps(n,c,l,s,t); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,s_data[5*i] , s_data[5*i+1] ); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s_data[5*i]+c[0], s_data[5*i+1]+c[1]); glVertex3f(s_data[5*i+2], s_data[5*i+3], s_data[5*i+4]); } // Bottom Face n[0]=0.0f; n[1]=-1.0f; n[2]=0.0f; s[0]=-1.0f; s[1]=0.0f; s[2]=0.0f; t[0]=0.0f; t[1]=0.0f; t[2]=-1.0f; for (i=12; i<16; i++) { c[0]=s_data[5*i+2]; c[1]=s_data[5*i+3]; c[2]=s_data[5*i+4]; SetUpBumps(n,c,l,s,t); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,s_data[5*i] , s_data[5*i+1] ); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s_data[5*i]+c[0], s_data[5*i+1]+c[1]); glVertex3f(s_data[5*i+2], s_data[5*i+3], s_data[5*i+4]); } // Right Face n[0]=1.0f; n[1]=0.0f; n[2]=0.0f; s[0]=0.0f; s[1]=0.0f; s[2]=-1.0f; t[0]=0.0f; t[1]=1.0f; t[2]=0.0f; for (i=16; i<20; i++) { c[0]=s_data[5*i+2]; c[1]=s_data[5*i+3]; c[2]=s_data[5*i+4]; SetUpBumps(n,c,l,s,t); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,s_data[5*i] , s_data[5*i+1] ); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s_data[5*i]+c[0], s_data[5*i+1]+c[1]); glVertex3f(s_data[5*i+2], s_data[5*i+3], s_data[5*i+4]); } // Left Face n[0]=-1.0f; n[1]=0.0f; n[2]=0.0f; s[0]=0.0f; s[1]=0.0f; s[2]=1.0f; t[0]=0.0f; t[1]=1.0f; t[2]=0.0f; for (i=20; i<24; i++) { c[0]=s_data[5*i+2]; c[1]=s_data[5*i+3]; c[2]=s_data[5*i+4]; SetUpBumps(n,c,l,s,t); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,s_data[5*i] , s_data[5*i+1] ); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s_data[5*i]+c[0], s_data[5*i+1]+c[1]); glVertex3f(s_data[5*i+2], s_data[5*i+3], s_data[5*i+4]); } glEnd(); /* PASS#2 Use Texture "Base" Blend GL_DST_COLOR To GL_SRC_COLOR (Multiplies By 2) Lighting Enabled No Offset Texture-Coordinates */ glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); if (!m_emboss) { glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D,m_texture[m_filter]); glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR); glEnable(GL_BLEND); glEnable(GL_LIGHTING); doCube(); } m_xrot+=m_xspeed; m_yrot+=m_yspeed; if (m_xrot>360.0f) m_xrot-=360.0f; if (m_xrot<0.0f) m_xrot+=360.0f; if (m_yrot>360.0f) m_yrot-=360.0f; if (m_yrot<0.0f) m_yrot+=360.0f; /* LAST PASS: Do The Logos! */ doLogo(); return true; // Keep Going }
void BindMultiTexture(const unsigned int channel, unsigned int id) { glActiveTextureARB(channel); glBindTexture(channel, id); }
void ShadowScene::renderEnvironment(bool m_bShadow){ MeshManager & meshManager = MeshManager::getInstance(); ShaderManager & shaderManager = ShaderManager::getInstance(); TextureManager & textureManager = TextureManager::getInstance(); glMaterialfv(GL_FRONT, GL_AMBIENT,m_fDarkGreyColor); glMaterialfv(GL_FRONT, GL_DIFFUSE,m_fWhiteColor); glMaterialfv(GL_FRONT, GL_SPECULAR,m_fWhiteColor); glMaterialf( GL_FRONT, GL_SHININESS, 100.0f); glDisable(GL_BLEND); glPushMatrix(); glTranslatef(m_fLightPosition[0],m_fLightPosition[1],m_fLightPosition[2]); glRotatef(fAngle,0.0,1.0,0.0); glTranslatef(m_fLightDistance[0],m_fLightDistance[1],m_fLightDistance[2]); glLightfv(GL_LIGHT0, GL_POSITION,m_fLightZeros); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION,m_fLightDirection); glPopMatrix(); if(!m_bShadow){ //display the light glPushMatrix(); glTranslatef(m_fLightPosition[0],m_fLightPosition[1],m_fLightPosition[2]); glRotatef(fAngle,0.0,1.0,0.0); glTranslatef(m_fLightDistance[0],m_fLightDistance[1],m_fLightDistance[2]); glScalef(0.02,0.02,0.02); glColor3f(0.0,0.0,0.0); meshManager.getMesh("cone.obj")->Draw(0); glColor3f(1.0,1.0,1.0); meshManager.getMesh("cone.obj")->Draw(1); glPopMatrix(); //enable the light shader shaderManager.getShader("light")->Activate(); shaderManager.getShader("light")->setUniformi("useShadowMap",1); shaderManager.getShader("light")->setUniformi("useTexture",1); //activate the shadowmap glActiveTextureARB(GL_TEXTURE7); m_pShadowMapFBO->activateDepthTexture(); glActiveTextureARB(GL_TEXTURE0); } ////// Temple ////// //transformation matrix for the shadow mapping if(!m_bShadow){ glPushMatrix(); glLoadIdentity(); glScalef(0.2,0.2,0.2); glGetFloatv(GL_MODELVIEW_MATRIX, transformationmatrix); shaderManager.getShader("light")->setUniformMatrix4fv("transmatrix",transformationmatrix); glPopMatrix(); glPushMatrix(); glScalef(0.2,0.2,0.2); shaderManager.getShader("light")->setUniformi("useBump",1); glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/stonefloor_diffuse.jpg")->activate(); glActiveTexture(GL_TEXTURE1); textureManager.getTexture2D("../../data/stonefloor_NM_height.tga")->activate(); meshManager.getMesh("sceneShadow.obj")->Draw(0);//floor meshManager.getMesh("sceneShadow.obj")->Draw(2);//columns meshManager.getMesh("sceneShadow.obj")->Draw(3);//pedestal glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/stonewall_diffuse.jpg.")->activate(); glActiveTexture(GL_TEXTURE1); textureManager.getTexture2D("../../data/stonewall_normals.jpg")->activate(); glMaterialf( GL_FRONT, GL_SHININESS, 20.0f); meshManager.getMesh("sceneShadow.obj")->Draw(4);//walls glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/rocks_diffuse.jpg.")->activate(); glActiveTexture(GL_TEXTURE1); textureManager.getTexture2D("../../data/rocks_NM_height.tga")->activate(); shaderManager.getShader("light")->setUniformi("useBump",0); shaderManager.getShader("light")->setUniformi("usePOM",1); shaderManager.getShader("light")->setUniformf("heightFactor",0.03f); meshManager.getMesh("sceneShadow.obj")->Draw(1);//ceiling glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/face_diffuse.jpg.")->activate(); glActiveTexture(GL_TEXTURE1); textureManager.getTexture2D("../../data/face_NM_height.png")->activate(); shaderManager.getShader("light")->setUniformf("heightFactor",0.1f); meshManager.getMesh("sceneShadow.obj")->Draw(6);//cube glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/stonefloor_diffuse.jpg")->desactivate(); glActiveTexture(GL_TEXTURE1); textureManager.getTexture2D("../../data/stonefloor_normal.jpg")->desactivate(); glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/wood.jpg.")->activate(); shaderManager.getShader("light")->setUniformi("usePOM",0); meshManager.getMesh("sceneShadow.obj")->Draw(5);//ladder glPopMatrix(); } else{ glPushMatrix(); glScalef(0.2,0.2,0.2); meshManager.getMesh("sceneShadow.obj")->Draw(); glPopMatrix(); } ////// END TEMPLE ////// ////// TEAPOT ////// if(!m_bShadow){ glPushMatrix(); glLoadIdentity(); glTranslatef(0.0,0.68,-10.0); glScalef(0.08,0.08,0.08); glGetFloatv(GL_MODELVIEW_MATRIX, transformationmatrix); shaderManager.getShader("light")->setUniformMatrix4fv("transmatrix",transformationmatrix); glPopMatrix(); glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/wand_boden_diffuse.jpg.")->activate(); } glPushMatrix(); glTranslatef(0.0,0.68,-10.0); glScalef(0.08,0.08,0.08); meshManager.getMesh("teapot.obj")->Draw();//floor if(!m_bShadow){ glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/wand_boden_diffuse.jpg")->desactivate(); } glPopMatrix(); ////// END TEAPOT ////// ////// SPIDER WEB ////// glMaterialfv(GL_FRONT, GL_SPECULAR,m_fBlackColor); glDisable(GL_CULL_FACE); if(!m_bShadow){ glPushMatrix(); glLoadIdentity(); glTranslatef(-2.0,2.0,-8.0); glRotatef(90,0.0,1.0,0.0); glScalef(0.7,0.7,0.7); glGetFloatv(GL_MODELVIEW_MATRIX, transformationmatrix); shaderManager.getShader("light")->setUniformMatrix4fv("transmatrix",transformationmatrix); glPopMatrix(); glEnable(GL_BLEND); } else{ shaderManager.getShader("simpleDiscard")->Activate(); } glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/web.png",false)->activate(); glPushMatrix(); glTranslatef(-2.0,2.0,-8.0); glRotatef(90,0.0,1.0,0.0); glScalef(0.7,0.7,0.7); meshManager.getMesh("plane.obj")->Draw();//web glActiveTexture(GL_TEXTURE0); textureManager.getTexture2D("../../data/web.png")->desactivate(); if(!m_bShadow){ glDisable(GL_BLEND); shaderManager.getShader("light")->Activate(); } else{ shaderManager.getShader("simpleDiscard")->Desactivate(); } glPopMatrix(); glEnable(GL_CULL_FACE); ////// END SPIDER WEB ////// shaderManager.getShader("light")->Desactivate(); if (m_bDisplaySpline) displaySpline(); }
void ParticleRenderer::display(DisplayMode mode /* = PARTICLE_POINTS */) { switch (mode) { case PARTICLE_POINTS: glColor3f(1, 1, 1); glPointSize(m_pointSize); _drawPoints(); break; case PARTICLE_SPRITES: default: { // setup point sprites glEnable(GL_POINT_SPRITE_ARB); glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); glPointSize(m_spriteSize); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glUseProgram(m_program); GLuint texLoc = glGetUniformLocation(m_program, "splatTexture"); glUniform1i(texLoc, 0); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, m_texture); glColor3f(1, 1, 1); glSecondaryColor3fv(m_baseColor); _drawPoints(); glUseProgram(0); glDisable(GL_POINT_SPRITE_ARB); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } break; case PARTICLE_SPRITES_COLOR: { // setup point sprites glEnable(GL_POINT_SPRITE_ARB); glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV); glPointSize(m_spriteSize); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glUseProgram(m_program); GLuint texLoc = glGetUniformLocation(m_program, "splatTexture"); glUniform1i(texLoc, 0); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, m_texture); glColor3f(1, 1, 1); glSecondaryColor3fv(m_baseColor); _drawPoints(true); glUseProgram(0); glDisable(GL_POINT_SPRITE_ARB); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } break; } CUT_CHECK_ERROR_GL(); }
void renderScene(void) { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(angleX,0.0,1.0,0.0); glRotatef(angleY,1.0,0.0,0.0); for(int i = 0; i<SIZE; i++) { glBegin(GL_LINE_STRIP); for(int j = 0; j<SIZE+1; j++) { float aj = (float)j / (float)HSIZE * 3.14159265f * 32; int a = i*(SIZE+1)+j; glVertex3fv(&(data[a].pos[0])); } glEnd(); } // rendering with shader glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, shape[ush] ); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, dtex[utx] ); lineShader->TurnOn(); float p[4]; glGetLightfv(GL_LIGHT0, GL_POSITION, &p[0]); lineShader->SetInt(profile, 0); lineShader->SetInt(texture, 1); lineShader->SetFloat4(haloColor, 0.0, 0.0, 0.0, 1.0); // glCallList(OBJECT_DISPLAYLIST); for(int i = 0; i<SIZE; i++) { glBegin(GL_QUAD_STRIP); for(int j = 0; j<SIZE+1; j++) { float aj = (float)j / (float)HSIZE * 3.14159265f * 32; int a = i*(SIZE+1)+j; renderStreamlineStrip(data[a]); } glEnd(); } lineShader->TurnOff(); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glPopMatrix(); glutSwapBuffers(); }
int ProgramUniformGLSL::Set(PLRenderer::TextureBuffer *pTextureBuffer) { // Valid texture unit? if (m_nTextureUnit >= 0) { // Get the OpenGL texture GLuint nOpenGLTexture = 0; GLenum nOpenGLTextureTarget = GL_TEXTURE_2D; if (pTextureBuffer) { // Check resource type switch (pTextureBuffer->GetType()) { case PLRenderer::Resource::TypeTextureBuffer1D: nOpenGLTexture = static_cast<TextureBuffer1D*>(pTextureBuffer)->GetOpenGLTexture(); nOpenGLTextureTarget = GL_TEXTURE_1D; break; case PLRenderer::Resource::TypeTextureBuffer2D: nOpenGLTexture = static_cast<TextureBuffer2D*>(pTextureBuffer)->GetOpenGLTexture(); nOpenGLTextureTarget = GL_TEXTURE_2D; break; case PLRenderer::Resource::TypeTextureBuffer2DArray: nOpenGLTexture = static_cast<TextureBuffer2DArray*>(pTextureBuffer)->GetOpenGLTexture(); nOpenGLTextureTarget = GL_TEXTURE_2D_ARRAY_EXT; break; case PLRenderer::Resource::TypeTextureBufferRectangle: nOpenGLTexture = static_cast<TextureBufferRectangle*>(pTextureBuffer)->GetOpenGLTexture(); nOpenGLTextureTarget = GL_TEXTURE_RECTANGLE_ARB; break; case PLRenderer::Resource::TypeTextureBuffer3D: nOpenGLTexture = static_cast<TextureBuffer3D*>(pTextureBuffer)->GetOpenGLTexture(); nOpenGLTextureTarget = GL_TEXTURE_3D_EXT; break; case PLRenderer::Resource::TypeTextureBufferCube: nOpenGLTexture = static_cast<TextureBufferCube*>(pTextureBuffer)->GetOpenGLTexture(); nOpenGLTextureTarget = GL_TEXTURE_CUBE_MAP_ARB; break; case PLRenderer::Resource::TypeIndexBuffer: case PLRenderer::Resource::TypeVertexBuffer: case PLRenderer::Resource::TypeUniformBuffer: case PLRenderer::Resource::TypeOcclusionQuery: case PLRenderer::Resource::TypeVertexShader: case PLRenderer::Resource::TypeTessellationControlShader: case PLRenderer::Resource::TypeTessellationEvaluationShader: case PLRenderer::Resource::TypeGeometryShader: case PLRenderer::Resource::TypeFragmentShader: case PLRenderer::Resource::TypeProgram: case PLRenderer::Resource::TypeFont: default: // Only texture types in this switch break; } } // Activate the texture unit the uniform is assigned to glActiveTextureARB(GL_TEXTURE0_ARB + m_nTextureUnit); // Bind the OpenGL texture glBindTexture(nOpenGLTextureTarget, nOpenGLTexture); // Assign the current bound texture at the current activated texture unit to the uniform glUniform1iARB(m_nOpenGLUniformLocation, m_nTextureUnit); // Inform the renderer if (pTextureBuffer) static_cast<Renderer&>(pTextureBuffer->GetRenderer()).SetShaderProgramTextureBuffer(m_nTextureUnit, pTextureBuffer); // Done, return the texture unit the uniform is assigned to return m_nTextureUnit; } // Error! return -1; }
/** * Test one cube map face to see if glGetTexImage from a cube face into * a PBO works correctly. */ static bool test_face(GLuint face) { const GLenum cubeFaceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face; const GLuint expectedColor = Colors[face]; GLuint texData[TEX_NUMPIXELS]; GLuint cubeTex, fbo, packPBO; GLuint f, i; void *ptr; /* Create the cubemap texture. */ glGenTextures(1, &cubeTex); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex); glPixelStorei(GL_UNPACK_ROW_LENGTH, TEX_WIDTH); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for (f = 0; f < 6; ++f) { for (i = 0; i < TEX_NUMPIXELS; ++i) { texData[i] = Colors[f]; } glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, 0, GL_SRGB8_ALPHA8, TEX_WIDTH, TEX_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, texData); } /* Setup the FBO. */ glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cubeFaceTarget, cubeTex, 0); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { printf("Incomplete framebuffer object\n"); return false; } glDrawBuffer(GL_COLOR_ATTACHMENT0); /* Read back cubemap face into PBO */ glGenBuffers(1, &packPBO); glBindBuffer(GL_PIXEL_PACK_BUFFER, packPBO); glBufferData(GL_PIXEL_PACK_BUFFER, TEX_NUMPIXELS * sizeof(GLuint), NULL, GL_STREAM_READ); glPixelStorei(GL_PACK_ROW_LENGTH, TEX_WIDTH); glPixelStorei(GL_PACK_ALIGNMENT, 1); glGetTexImage(cubeFaceTarget, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); /* Map pack PBO to get results. */ ptr = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); if (!ptr) { printf("failed to map PBO\n"); return false; } for (i = 0; i < TEX_NUMPIXELS; ++i) { texData[i] = Colors[6]; /* gray */ } memcpy(texData, ptr, TEX_NUMPIXELS * sizeof(GLuint)); glUnmapBuffer(GL_PIXEL_PACK_BUFFER); if (expectedColor != texData[0]) { printf("Colors don't match for face %u\n", face); printf("Expected 0x%08x but found 0x%08x \n", expectedColor, texData[0]); return false; } glDeleteTextures(1, &cubeTex); glDeleteFramebuffers(1, &fbo); glDeleteBuffers(1, &packPBO); /* if we get here we passed */ return true; }
//=========================================================================== // activeTexture //=========================================================================== void activeTexture(const GLenum texture) { #ifdef USE_MULTITEXTURE glActiveTextureARB(texture); #endif }
bool CRenderSystemGL::ResetRenderSystem(int width, int height, bool fullScreen, float refreshRate) { m_width = width; m_height = height; glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); CalculateMaxTexturesize(); CRect rect( 0, 0, width, height ); SetViewPort( rect ); glEnable(GL_TEXTURE_2D); glEnable(GL_SCISSOR_TEST); glMatrixProject.Clear(); glMatrixModview->LoadIdentity(); glMatrixProject->Ortho(0.0f, width-1, height-1, 0.0f, -1.0f, 1.0f); glMatrixProject.Load(); glMatrixModview.Clear(); glMatrixModview->LoadIdentity(); glMatrixModview.Load(); glMatrixTexture.Clear(); glMatrixTexture->LoadIdentity(); glMatrixTexture.Load(); if (glewIsSupported("GL_ARB_multitexture")) { //clear error flags ResetGLErrors(); GLint maxtex; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &maxtex); //some sanity checks GLenum error = glGetError(); if (error != GL_NO_ERROR) { CLog::Log(LOGERROR, "ResetRenderSystem() GL_MAX_TEXTURE_IMAGE_UNITS_ARB returned error %i", (int)error); maxtex = 3; } else if (maxtex < 1 || maxtex > 32) { CLog::Log(LOGERROR, "ResetRenderSystem() GL_MAX_TEXTURE_IMAGE_UNITS_ARB returned invalid value %i", (int)maxtex); maxtex = 3; } //reset texture matrix for all textures for (GLint i = 0; i < maxtex; i++) { glActiveTextureARB(GL_TEXTURE0 + i); glMatrixTexture.Load(); } glActiveTextureARB(GL_TEXTURE0); } glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); // Turn Blending On glDisable(GL_DEPTH_TEST); return true; }
void FrameBufferObject::Bind(GLint unit) const { glActiveTextureARB(GL_TEXTURE0_ARB + unit); glEnable(m_eTextureType); glBindTexture(m_eTextureType, m_nTexId); }
// Function of L-BFGS-B void funcgrad(real* x, real& f, real* g, const cudaStream_t& stream) { int i,j; get_timestamp(start_time_func); ////////////////////////////////////////////// // First pass - Render the initial sites // ////////////////////////////////////////////// // FB_objects에 Processed_Texture[0]을 반영 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FB_objects); // 결과가 Processed_Texture[0]에 반영되도록 설정 // fbo_attachments는 ColorAttachemnt 번호 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Processed_Texture[0], 0); CheckFramebufferStatus(); // 출력할 버퍼를 선정 glDrawBuffer(fbo_attachments[0]); glClearColor(-1, -1, -1, -1); glClear(GL_COLOR_BUFFER_BIT); cgGLEnableProfile(VertexProfile); cgGLEnableProfile(FragmentProfile); cgGLBindProgram(VP_DrawSites); cgGLBindProgram(FP_DrawSites); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(1, screenwidth+1, 1, screenheight+1); glViewport(1, 1, screenwidth, screenheight); DrawSites(x, stream); // glReadBuffer(fbo_attachments[0]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA, "funcgrad - First Pass"); Current_Buffer = 1; // 다음에 사용할 Texture를 선정 ///////////////////////////////////// // Second pass - Flood the sites // ///////////////////////////////////// cgGLBindProgram(VP_Flood); cgGLBindProgram(FP_Flood); if (VP_Flood_Size != NULL) cgSetParameter2f(VP_Flood_Size, screenwidth, screenheight); bool ExitLoop = false; bool SecondExit; int steplength;; SecondExit = (additional_passes==0); bool PassesBeforeJFA; PassesBeforeJFA = (additional_passes_before>0); if (PassesBeforeJFA) steplength = pow(2.0, (additional_passes_before-1)); else steplength = (screenwidth>screenheight ? screenwidth : screenheight)/2; while (!ExitLoop) { // Pixel 단위로 값을 저장하고 있는 Processed_Texture를 VertextBuffer로 사용??? glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[Current_Buffer], GL_TEXTURE_RECTANGLE_NV, Processed_Texture[Current_Buffer], 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[Current_Buffer]); glClearColor(-1, -1, -1, -1); glClear(GL_COLOR_BUFFER_BIT); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1-Current_Buffer]); if (VP_Flood_Steplength != NULL) cgSetParameter1d(VP_Flood_Steplength, steplength); glBegin(GL_QUADS); glVertex2f(1.0, 1.0); glVertex2f(1.0, float(screenheight+1)); glVertex2f(float(screenwidth+1), float(screenheight+1)); glVertex2f(float(screenwidth+1), 1.0); glEnd(); // glReadBuffer(fbo_attachments[Current_Buffer]); // imdebugPixelsf(0, 0, screenwidth+2, screenheight+2, GL_RGBA); // funcgrad가 2번 이상 호출하는 경우를 위한 초기화 코드 if (steplength==1 && PassesBeforeJFA) { steplength = (screenwidth>screenheight ? screenwidth : screenheight)/2; PassesBeforeJFA = false; } else if (steplength>1) steplength /= 2; else if (SecondExit) ExitLoop = true; else { steplength = pow(2.0, (additional_passes-1)); SecondExit = true; } // Loop를 돌 때마다 다른 버퍼를 사용하도록 처리 Current_Buffer = 1-Current_Buffer; } //////////////////////////////// // Third pass, Compute energy // //////////////////////////////// cgGLBindProgram(VP_Scatter); cgGLBindProgram(FP_Scatter); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, fbo_attachments[0], GL_TEXTURE_RECTANGLE_NV, Site_Texture, 0); CheckFramebufferStatus(); glDrawBuffer(fbo_attachments[0]); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); if (VP_Scatter_Size != NULL) cgSetParameter2f(VP_Scatter_Size, screenwidth, screenheight); //Bind & enable shadow map texture glActiveTextureARB(GL_TEXTURE0_ARB); // Loop 종료시 CurrentBuffer를 변경하기 때문에 // 완료된 버퍼를 사용하기 위해 1-Current_Buffer를 선택 glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1-Current_Buffer]); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glCallList(ScreenPointsList); glDisable(GL_BLEND); Energyf(grSite, g, f_tb_dev, screenwidth, iSiteTextureHeight, point_num, stream); lbfgsbcuda::CheckBuffer(g, point_num * 2, point_num * 2); glFinish(); get_timestamp(end_time_func); elapsed_time_func = (end_time_func-start_time_func); total_time_func += elapsed_time_func; // energyf()의 결과를 반환 f = *f_tb_host; }
void FrameBufferObject::Unbind(GLint unit) const { glActiveTextureARB(GL_TEXTURE0_ARB + unit); glBindTexture( m_eTextureType, 0 ); glDisable(m_eTextureType); }
void InitializeGlut(int *argc, char *argv[]) { int i,j; glutInit(argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(screenwidth, screenheight); glutCreateWindow(argv[0]); glutDisplayFunc(Display); glutKeyboardFunc(Keyboard); // Support mapped pinned allocations cudaSetDeviceFlags(cudaDeviceMapHost); cudaGLSetGLDevice(0); cublasCreate_v2(&cublasHd); glewInit(); GLint max_texture_size; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); if(max_texture_size < screenwidth || screenwidth < screenheight) { printf("Max size of texttur(%d) is less than screensize(%d, %d)\n", max_texture_size, screenwidth, screenheight); exit(0); } //Create the textures glActiveTextureARB(GL_TEXTURE0_ARB); // 처리용 텍스쳐 2장 // Q. 왜 2장일까? glGenTextures(2, Processed_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[0]); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA32F_ARB, screenwidth+2, screenheight+2, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Processed_Texture[1]); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA32F_ARB, screenwidth+2, screenheight+2, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); // Site용 텍스쳐 // Q. 처리용과 별개인 이유는? glGenTextures(1, &Site_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Site_Texture); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA32F_ARB, screenwidth+2, screenheight+2, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); // Registers the texture or renderbuffer object specified by image for access by CUDA. // A handle to the registered object is returned as resource cutilSafeCall(cudaGraphicsGLRegisterImage(&grSite, Site_Texture, GL_TEXTURE_RECTANGLE_NV, cudaGraphicsMapFlagsReadOnly)); // 에너지용 텍스쳐 // 처리용과 동일한 2장 // Q. 왜?? glGenTextures(2, Energy_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Energy_Texture[0]); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA32F_ARB, screenwidth+2, screenheight+2, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); glBindTexture(GL_TEXTURE_RECTANGLE_NV, Energy_Texture[1]); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA32F_ARB, screenwidth+2, screenheight+2, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); // 인덱스용 텍스쳐 // 인덱스를 컬러로 표현 glGenTextures(1, &IndexColor_Texture); glBindTexture(GL_TEXTURE_RECTANGLE_NV, IndexColor_Texture); glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGBA, screenwidth, screenheight, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP); // Render Buffer Object glGenFramebuffersEXT(1, &RB_object); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, RB_object); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, screenwidth+2, screenheight+2); // Frame(?) Buffer Object glGenFramebuffersEXT(1, &FB_objects); // ???? // NVIDIA 확인이라는 점만 확인 // http://developer.download.nvidia.com/opengl/specs/nvOpenGLspecs.pdf glGetQueryiv(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &oq_bitsSupported); glGenQueriesARB(1, &occlusion_query); InitCg(); // 미리 컴파일된 화면 픽셀 목록 ScreenPointsList = glGenLists(1); glNewList(ScreenPointsList, GL_COMPILE); glBegin(GL_POINTS); for (i=0; i<screenwidth; i++) for (j=0; j<screenheight; j++) glVertex2f(i+1.5, j+1.5); glEnd(); glEndList(); }
static void ActiveTexture(int i) { glActiveTextureARB(i); }
void BL_Texture::ActivateFirst() { if(GLEW_ARB_multitexture) glActiveTextureARB(GL_TEXTURE0_ARB); }
void __stdcall glActiveTexture(GLenum texture) { if (!ARB_multitexture) return; glActiveTextureARB(texture); //MessageBox(NULL, "glActiveTexture", "glExt", MB_OK); }