void CTriangleObj::glDrawElementFaceGoround(const int eid, void* mirrorred) { Vector3i*& m_pTriangle = (Vector3i*&)m_pPolygon; Vector3f normal = m_pPolyNorm[eid]; if (mirrorred) normal = -normal; glNormal3fv(&normal.x); const Vector3i tri = m_pTriangle[eid]; const Vector3d *v0= &m_pVertex[tri.x]; const Vector3d *v1= &m_pVertex[tri.y]; const Vector3d *v2= &m_pVertex[tri.z]; if (this->NeedTexture1D() && m_pVertexTexCoor1D){ const float tx = m_pVertexTexCoor1D[tri.x]; const float ty = m_pVertexTexCoor1D[tri.y]; const float tz = m_pVertexTexCoor1D[tri.z]; glTexCoord1f(tx); glVertex3dv(&v0->x); glTexCoord1f(ty); glVertex3dv(&v1->x); glTexCoord1f(tz); glVertex3dv(&v2->x); } else{ glVertex3dv(&v0->x); glVertex3dv(&v1->x); glVertex3dv(&v2->x); } }
/* ---------------------------------------------------------- */ void subdivide(GLfloat v1[2], GLfloat v2[2],GLfloat v3[2], int depth) { int i; GLfloat v12[2], v23[2], v31[2]; if (!depth) { GLfloat P0[3],P1[3],P2[3],t0,t1,t2; getPoint(P0,&t0,v1[0],v1[1]);glTexCoord1f(t0);glVertex3fv(P0); getPoint(P1,&t1,v2[0],v2[1]);glTexCoord1f(t1);glVertex3fv(P1); getPoint(P2,&t2,v3[0],v3[1]);glTexCoord1f(t2);glVertex3fv(P2); } else { for (i = 0; i < 2; i++) { v12[i] = (v1[i]+v2[i])/2.0f; v23[i] = (v2[i]+v3[i])/2.0f; v31[i] = (v3[i]+v1[i])/2.0f; } subdivide(v1 ,v12,v31 ,depth-1); subdivide(v31,v12,v23 ,depth-1); subdivide(v23,v12,v2 ,depth-1); subdivide(v31,v23,v3 ,depth-1); } }
void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); GLint k; GLubyte texLine[16]; for( k = 0 ; k <=2 ; k+= 2) { texLine[4*k] = 0; texLine[4*k + 1] = 255; texLine[4*k + 2] = 0; texLine[4*k + 3] = 255; } for( k = 1 ; k <=3 ; k+= 2) { texLine[4*k] = 255; texLine[4*k + 1] = 0; texLine[4*k + 2] = 0; texLine[4*k + 3] = 255; } glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,4,0,GL_RGBA,GL_UNSIGNED_BYTE,texLine); float v1[3] = { 10.0f, 200.0f,0.0f}; float v2[3] = { 200.0f,200.0f,0.0f}; glEnable(GL_TEXTURE_1D); glBegin(GL_LINES); glTexCoord1f(-2.0); glVertex3fv(v1); glTexCoord1f(2.0); glVertex3fv(v2); glEnd(); glDisable(GL_TEXTURE_1D); glFlush(); }
void SpectrumVisualizer::draw() { glClear(GL_COLOR_BUFFER_BIT); if (this->factory.enable_grid) this->drawGrid(); this->data_mutex.lock(); this->shader.bind(); this->shader.bindTextureToUniform("palette", this->palette, 0); glLineWidth(1.0f); glBegin(GL_LINE_STRIP); // We start at i = 1 because we do not want to draw the DC component // that is stored at i = 0. for (unsigned int i = 1; i < this->spectrum.size(); i++) { float frequency = this->stft.getFrequencies()[i]; float x = this->frequency2xCoordinate(frequency); float y = this->spectrum[i]; float normalized_magnitude = (y - this->factory.dB_min) / (this->factory.dB_clip - this->factory.dB_min); glTexCoord1f(normalized_magnitude); glVertex2f(x, y); } glEnd(); this->shader.unbind(); this->data_mutex.unlock(); }
void CPointObj::glDrawElementFaceGoround(const int eid, void *pvoid) { ASSERT0(eid>=0 && eid<m_nVertexCount); Vector3d& v = m_pVertex[eid]; bool reverse_normal=false; if (pvoid) reverse_normal=true; if (this->NeedTexture1D() && m_pVertexTexCoor1D){ const float tx = m_pVertexTexCoor1D[eid]; glTexCoord1f(tx); } if (!m_pMatrix){ float r=0; if (m_pRadius) r= m_pRadius[eid]; if (r==0) r = m_fGivenRad; r *= m_pDrawParms->m_fVertexSizeScale; CSphere16::getInstance().glDraw(v, r, reverse_normal); } else{ Vector3f vf(v.x, v.y, v.z); float3x3 mat = m_pMatrix[eid]*m_pDrawParms->m_fVertexSizeScale; mat.Transpose(); CSphere16::getInstance().glDraw(vf, mat, reverse_normal); } }
/* Start GL_ARB_multitexture emulation */ static void WINE_GLAPI wine_glMultiTexCoord1fARB(GLenum target, GLfloat s) { if(target != GL_TEXTURE0) { ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n"); return; } glTexCoord1f(s); }
void VisusMeshDisplay::renderColoredFlat() { std::vector<VisusMeshData::IndexDataType>::iterator it; glShadeModel(GL_FLAT); switch (mMesh.elementDim()) { case 3: glBegin(GL_TRIANGLES); break; case 4: glBegin(GL_QUADS); break; default: glBegin(GL_POLYGON); break; } for (uint32_t i=0;i<mMesh.nrOfElements();i++) { std::vector<VisusMeshData::IndexDataType>& element = mMesh.element(i); for (it=element.begin();it!=element.end();it++) { VisusMeshData::IndexDataType idx = *it; glTexCoord1f(mMesh.vertex(idx)[mColorIndex]); glVertex3fv(mMesh.vertexAddress(idx)); } } glEnd(); }
static void draw_triangles() { struct triangle_t* cursor=mesh.triangles; glBegin(GL_TRIANGLES); while (cursor) { struct vertex_t* v0=mesh.vertices+cursor->i0; struct vertex_t* v1=mesh.vertices+cursor->i1; struct vertex_t* v2=mesh.vertices+cursor->i2; glNormal3f(-v0->nx,-v0->ny,-v0->nz);glTexCoord1f(0.5f*(v0->y+1));glVertex3f(v0->x,v0->y,v0->z); glNormal3f(-v1->nx,-v1->ny,-v1->nz);glTexCoord1f(0.5f*(v1->y+1));glVertex3f(v1->x,v1->y,v1->z); glNormal3f(-v2->nx,-v2->ny,-v2->nz);glTexCoord1f(0.5f*(v2->y+1));glVertex3f(v2->x,v2->y,v2->z); cursor=cursor->next; } glEnd(); }
static void draw( void ) { glClear( GL_COLOR_BUFFER_BIT ); glColor3f( 1.0, 1.0, 1.0 ); /* draw first polygon */ glPushMatrix(); glTranslatef( -1.0, 0.0, 0.0 ); glRotatef( Angle, 0.0, 0.0, 1.0 ); glBindTexture( GL_TEXTURE_1D, TexObj[0] ); glBegin( GL_POLYGON ); glTexCoord1f( 0.0 ); glVertex2f( -1.0, -1.0 ); glTexCoord1f( 1.0 ); glVertex2f( 1.0, -1.0 ); glTexCoord1f( 1.0 ); glVertex2f( 1.0, 1.0 ); glTexCoord1f( 0.0 ); glVertex2f( -1.0, 1.0 ); glEnd(); glPopMatrix(); glutSwapBuffers(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cgGLBindProgram(cg_vertex_program); checkForCgError("binding vertex program"); cgGLEnableProfile(cg_vertex_profile); checkForCgError("enabling vertex profile"); // parameter //cgGLSetParameter1f(cg_parameter_vertex_scale_factor, 0.7); //cgGLSetParameter1f(cg_parameter_vertex_rotation, rotation); // Zeit die seit dem rendern des letzten Bildes vergangen ist: cgGLEnableTextureParameter(cg_parameter_vertex_time); t = diff_seconds(); glVertex2f(0.0f, 0.0f); glTexCoord1f(Particle->t); cgGLDisableTextureParameter(cg_parameter_vertex_time); // Berechnung der Framerate mit Hilfe der Zeitmessungsfunktion: frames++; timer += t; if (timer > 1.0) { printf("Frames per second: %i\n", frames); timer -= 1.0; frames = 0; printf("Number of particles: %d\n", water_list.size()); } //cgGLEnableTextureParameter(cg_parameter_vertex_velocity); drawParticles(water_list,water_tex); //glVertex2f(0.0f, 0.0f); //glTexCoord3fv(Particle->velocity); //cgGLDisableTextureParameter(cg_parameter_vertex_velocity); cgGLDisableProfile(cg_vertex_profile); checkForCgError("disabling vertex profile"); glutSwapBuffers(); }
void Glyphs::color_glyph(int i, int j) { int idx = (j * DIM) + i; double v; switch (scalar_field) { case SCALAR_WHITE: glColor3f(1,1,1); return; case SCALAR_DIR: direction_to_color(vf_x[idx],vf_y[idx]); return; case SCALAR_RHO: v = rho[idx]; break; case SCALAR_VELOC_MAG: v = v_mag[idx]; break; case SCALAR_FORCE_MAG: v = f_mag[idx]; break; } double out_min = 0, out_max = 1; // considering that values on the simulation and visualization range 0-1 (which they don't!) if (clamp_flag) { if (v > clamp_max) v = clamp_max; if (v < clamp_min) v = clamp_min; // map interval clamp_min - clamp_max -> out_min - out_max v = (v - clamp_min) * (out_max - out_min) / (clamp_max - clamp_min) + out_min; } if (scaling_flag) v = (v - dataset_min) * (out_max - out_min) / (dataset_max - dataset_min) + out_min; glTexCoord1f(v); }
void CTriangleObj::glDrawElementLine(const int eid, const float offset, const bool needtex) { Vector3i*& m_pTriangle = (Vector3i*&)m_pPolygon; Vector3d p0, p1, p2, *vt = m_pVertex; Vector3d displacement(0,0,0); Vector3i &quad = m_pTriangle[eid]; int v0=quad.x, v1=quad.y, v2=quad.z; if (fabs(offset)>1E-12){ Vector3f &norm = m_pPolyNorm[eid]; displacement.x = offset*norm.x; displacement.y = offset*norm.y; displacement.z = offset*norm.z; p0 = vt[v0] + displacement; p1 = vt[v1] + displacement; p2 = vt[v2] + displacement; } else{ p0 = vt[v0]; p1 = vt[v1]; p2 = vt[v2]; } // if (v0<v1){ if (needtex && m_pVertexTexCoor1D) glTexCoord1f(m_pVertexTexCoor1D[v0]); glVertex3dv(&p0.x); if (needtex && m_pVertexTexCoor1D) glTexCoord1f(m_pVertexTexCoor1D[v1]); glVertex3dv(&p1.x); // } // if (v1<v2){ if (needtex && m_pVertexTexCoor1D) glTexCoord1f(m_pVertexTexCoor1D[v1]); glVertex3dv(&p1.x); if (needtex && m_pVertexTexCoor1D) glTexCoord1f(m_pVertexTexCoor1D[v2]); glVertex3dv(&p2.x); // } // if (v2<v0){ if (needtex && m_pVertexTexCoor1D) glTexCoord1f(m_pVertexTexCoor1D[v2]); glVertex3dv(&p2.x); if (needtex && m_pVertexTexCoor1D) glTexCoord1f(m_pVertexTexCoor1D[v0]); glVertex3dv(&p0.x); // } }
///////////////////////////////////////////////////////// // Render // void GEMglTexCoord1f :: render(GemState *state) { glTexCoord1f (s); }
void nuiGLDrawContext::DrawShade (const nuiRect& rSourceRect, const nuiRect& rShadeRect) { // return; bool blending = mCurrentState.mBlending; GLenum blendfunc1,blendfunc2; blendfunc1 = mCurrentState.mBlendSourceFactor; blendfunc2 = mCurrentState.mBlendDestinationFactor; EnableBlending(true); SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); nuiSize ShadeSize = rSourceRect.mLeft - rShadeRect.mLeft; // Left shadow uint8 pLUT[256*4]; uint i; for (i = 0; i<256; i++) { pLUT[0+(i*4)] = 0; pLUT[1+(i*4)] = 0; pLUT[2+(i*4)] = 0; pLUT[3+(i*4)] = i; } EnableTexture2D(false); EnableTexture1D(true); glBindTexture(GL_TEXTURE_1D,0); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pLUT); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glBegin(GL_QUADS); glColor4f(0,0,0,0); glTexCoord1f(0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); glTexCoord1f(1); glVertex2f(rSourceRect.mLeft,rSourceRect.mTop); glColor4f(0,0,0,SHADE_ALPHA); glTexCoord1f(1); glVertex2f(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); glTexCoord1f(0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); glEnd(); EnableTexture1D(false); glBegin(GL_QUADS); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); glEnd(); // bottom shadow glBegin(GL_QUADS); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); glEnd(); // Right shadow EnableTexture1D(true); glBegin(GL_QUADS); glColor4f(0,0,0,0); glTexCoord1f(1); glVertex2f(rSourceRect.mRight,rSourceRect.mTop); glTexCoord1f(0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mTop); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); glTexCoord1f(1); glVertex2f(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); glEnd(); EnableTexture1D(false); glBegin(GL_QUADS); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); glEnd(); EnableTexture1D(true); glBegin(GL_QUADS); // Right Corner glColor4f(0,0,0,SHADE_ALPHA); glTexCoord1f(1); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); glColor4f(0,0,0,0); glTexCoord1f(0); glVertex2f(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); // Left Corner: glColor4f(0,0,0,0); glTexCoord1f(1); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); glColor4f(0,0,0,SHADE_ALPHA); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom); glColor4f(0,0,0,SHADE_ALPHA); glTexCoord1f(0); glVertex2f(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); glColor4f(0,0,0,0); glVertex2f(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom+ShadeSize); glEnd(); EnableTexture1D(false); EnableBlending(blending); SetBlendFunc(blendfunc1, blendfunc2); }
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 OglColorMap::drawVisual(const core::visual::VisualParams* vparams) { if( !vparams->displayFlags().getShowVisual() ) return; if (!f_showLegend.getValue()) return; // Prepare texture for legend // crashes on mac in batch mode (no GL context) if (vparams->isSupported(core::visual::API_OpenGL) && !texture) { glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_1D, texture); //glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); int width = getNbColors(); unsigned char *data = new unsigned char[ width * 3 ]; for (int i=0; i<width; i++) { Color c = getColor(i); data[i*3+0] = (unsigned char)(c[0]*255); data[i*3+1] = (unsigned char)(c[1]*255); data[i*3+2] = (unsigned char)(c[2]*255); } glBindTexture(GL_TEXTURE_1D, texture); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, width, 0, GL_RGB, GL_UNSIGNED_BYTE, data); delete[] data; } // // Draw legend // // TODO: move the code to DrawTool const std::string& legendTitle = f_legendTitle.getValue(); int yoffset = legendTitle.empty() ? 0 : 25; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT,viewport); const int vWidth = viewport[2]; const int vHeight = viewport[3]; glPushAttrib(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_BLEND); // disable clipping planes for(int i = 0; i < GL_MAX_CLIP_PLANES; ++i) glDisable(GL_CLIP_PLANE0+i); // Setup orthogonal projection glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, vWidth, vHeight, 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); #ifdef SOFA_HAVE_GLEW for(int i = 0; i < 8; ++i) { glActiveTexture(GL_TEXTURE0 + i); glDisable(GL_TEXTURE_2D); } glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, texture); //glBlendFunc(GL_ONE, GL_ONE); glColor3f(1.0f, 1.0f, 1.0f); GLhandleARB currentShader = sofa::helper::gl::GLSLShader::GetActiveShaderProgram(); sofa::helper::gl::GLSLShader::SetActiveShaderProgram(0); #endif // SOFA_HAVE_GLEW glBegin(GL_QUADS); glTexCoord1f(1.0); glVertex3f(20.0f+f_legendOffset.getValue().x(), yoffset+20.0f+f_legendOffset.getValue().y(), 0.0f); glTexCoord1f(1.0); glVertex3f(10.0f+f_legendOffset.getValue().x(), yoffset+20.0f+f_legendOffset.getValue().y(), 0.0f); glTexCoord1f(0.0); glVertex3f(10.0f+f_legendOffset.getValue().x(), yoffset+120.0f+f_legendOffset.getValue().y(), 0.0f); glTexCoord1f(0.0); glVertex3f(20.0f+f_legendOffset.getValue().x(), yoffset+120.0f+f_legendOffset.getValue().y(), 0.0f); glEnd(); glDisable(GL_TEXTURE_1D); // Restore model view matrix glPopMatrix(); // GL_MODELVIEW // Restore projection matrix glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); // Adjust the text color according to the background luminance GLfloat bgcol[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE,bgcol); Color textcolor(1.0f, 1.0f, 1.0f, 1.0f); static const sofa::defaulttype::Vec3f luminanceMatrix(0.212f, 0.715f, 0.072f); float backgroundLuminance = sofa::defaulttype::Vec3f(bgcol[0], bgcol[1], bgcol[2]) * luminanceMatrix; if(backgroundLuminance > 0.5f) textcolor = Color(0.0f, 0.0f, 0.0f, 1.0f); if( !legendTitle.empty() ) { vparams->drawTool()->writeOverlayText((int)f_legendOffset.getValue().x(), // x (int)f_legendOffset.getValue().y(), // y 11u, // size textcolor, legendTitle.c_str()); } // Maximum & minimum std::ostringstream smin, smax; smin << d_min.getValue() * d_legendRangeScale.getValue(); smax << d_max.getValue() * d_legendRangeScale.getValue(); vparams->drawTool()->writeOverlayText((int)f_legendOffset.getValue().x(), // x yoffset + (int)f_legendOffset.getValue().y(), // y 12u, // size textcolor, smax.str().c_str()); vparams->drawTool()->writeOverlayText((int)f_legendOffset.getValue().x(), // x yoffset + 120 + (int)f_legendOffset.getValue().y(), // y 12u, // size textcolor, smin.str().c_str()); #ifdef SOFA_HAVE_GLEW sofa::helper::gl::GLSLShader::SetActiveShaderProgram(currentShader); #endif // SOFA_HAVE_GLEW // Restore state glPopAttrib(); }
void TransFuncOverlay::process() { #ifndef VRN_MODULE_FONTRENDERING LWARNING("Empty output, enable module 'fontrendering'."); return; #endif tgtAssert(outport_.isReady(), "Outport not ready"); tgtAssert(imageInport_.isReady(), "Inport not ready"); tgtAssert(program_ && copyShader_, "Shader missing"); if(dynamic_cast<TransFunc1DKeys*>(transferFunc_.get()) == 0){ LWARNING("No transfer function of class TransFuncIntensity is given!!!"); return; } TransFunc1DKeys* tfi = dynamic_cast<TransFunc1DKeys*>(transferFunc_.get()); //render overlay privatePort_.activateTarget(); glPushAttrib(GL_ALL_ATTRIB_BITS); glClearColor(fontColor_.get().r,fontColor_.get().g,fontColor_.get().b,0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //render the transfer function texture const tgt::Texture* tfTex = 0; if(renderPreIntegrationTable_.get()) tfTex = tfi->getPreIntegrationTable(1.0f / (41.0f * 2.0f))->getTexture(); else tfTex = tfi->getTexture(); tgtAssert(tfTex, "No transfer function texture"); tfTex->bind(); glColor4f(1.f,1.f,1.f,1.f); glDisable(GL_DEPTH_TEST); glBegin(GL_QUADS); glVertex2f(-0.8f,-0.9f); glVertex2f(-0.5f,-0.9f); glVertex2f(-0.5f,0.7f); glVertex2f(-0.8f,0.7f); glEnd(); glColor4f(0.8f,0.8f,0.8f,1.f); glBegin(GL_QUADS); glVertex2f(-0.8f,-0.9f); glVertex2f(-0.65f,-0.9f); glVertex2f(-0.65f,-0.58f); glVertex2f(-0.8f,-0.58f); glVertex2f(-0.65f,-0.58f); glVertex2f(-0.5f,-0.58f); glVertex2f(-0.5f,-0.26f); glVertex2f(-0.65f,-0.26f); glVertex2f(-0.8f,-0.26f); glVertex2f(-0.65f,-0.26f); glVertex2f(-0.65f,0.06f); glVertex2f(-0.8f,0.06f); glVertex2f(-0.65f,0.06f); glVertex2f(-0.5f,0.06f); glVertex2f(-0.5f,0.38f); glVertex2f(-0.65f,0.38f); glVertex2f(-0.8f,0.38f); glVertex2f(-0.65f,0.38f); glVertex2f(-0.65f,0.7f); glVertex2f(-0.8f,0.7f); glEnd(); glColor4f(1.f,1.f,1.f,1.f); if(renderPreIntegrationTable_.get()) glEnable(GL_TEXTURE_2D); else glEnable(GL_TEXTURE_1D); glEnable(GL_BLEND); glBlendColor(0.0f,0.0f,0.0f,overlayOpacity_.get()); glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_CONSTANT_ALPHA); glBegin(GL_QUADS); if(renderPreIntegrationTable_.get()) { glTexCoord2f(0.f, 0.f); glVertex2f(-0.8f,-0.9f); glTexCoord2f(1.f, 0.f); glVertex2f(-0.5f,-0.9f); glTexCoord2f(1.f, 1.f); glVertex2f(-0.5f,0.7f); glTexCoord2f(0.f, 1.f); glVertex2f(-0.8f,0.7f); } else { glTexCoord1f(0.f); glVertex2f(-0.8f,-0.9f); glTexCoord1f(0.f); glVertex2f(-0.5f,-0.9f); glTexCoord1f(1.f); glVertex2f(-0.5f,0.7f); glTexCoord1f(1.f); glVertex2f(-0.8f,0.7f); } glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_1D); glEnable(GL_DEPTH_TEST); //render fonts glPushMatrix(); glTranslatef(-1.f,-1.f,0.f); float scaleFactorX = 2.0f / (float)privatePort_.getSize().x; float scaleFactorY = 2.0f / (float)privatePort_.getSize().y; glScalef(scaleFactorX, scaleFactorY, 1.f); glColor4f(fontColor_.get().r,fontColor_.get().g,fontColor_.get().b,fontColor_.get().a*overlayOpacity_.get()); fontProp_.get()->setSize(privatePort_.getSize().y/12); fontProp_.get()->setVerticalTextAlignment(tgt::Font::Middle); fontProp_.get()->setFontType(tgt::Font::BitmapFont); fontProp_.get()->setLineWidth(privatePort_.getSize().x*0.35f); fontProp_.get()->setTextAlignment(tgt::Font::Center); fontProp_.get()->render(tgt::vec3(0,privatePort_.getSize().y*0.925f,0), tfUnit_.get()); fontProp_.get()->setLineWidth((float)privatePort_.getSize().x); fontProp_.get()->setTextAlignment(tgt::Font::Left); std::stringstream strstr; strstr << tfi->getDomain(0).x * scalingProp_.get(); fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.05f,0), strstr.str()); strstr.clear(); strstr.str(""); strstr << (tfi->getDomain(0).x+((tfi->getDomain(0).y-tfi->getDomain(0).x)/2)) * scalingProp_.get(); fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.45f,0), strstr.str()); strstr.clear(); strstr.str(""); strstr << tfi->getDomain(0).y * scalingProp_.get(); fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.85f,0), strstr.str()); glPopMatrix(); glPopAttrib(); // render border around overlay if (renderBorder_.get()) { glPushAttrib(GL_ALL_ATTRIB_BITS); glColor4f(borderColor_.get().r,borderColor_.get().g,borderColor_.get().b,borderColor_.get().a*overlayOpacity_.get()); glLineWidth(borderWidth_.get()); glDepthFunc(GL_ALWAYS); glBegin(GL_LINE_STRIP); glVertex2f(-0.8f,-0.9f); glVertex2f(-0.5f,-0.9f); glVertex2f(-0.5f,0.7f); glVertex2f(-0.8f,0.7f); glVertex2f(-0.8f,-0.9f); glEnd(); glPopAttrib(); } LGL_ERROR; privatePort_.deactivateTarget(); //same code as in ImageOverlay // | // v outport_.activateTarget(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // bind input image to tex unit TextureUnit imageUnit, imageUnitDepth; imageInport_.bindTextures(imageUnit.getEnum(), imageUnitDepth.getEnum()); // 1. copy input image to outport copyShader_->activate(); setGlobalShaderParameters(copyShader_); imageInport_.setTextureParameters(copyShader_, "texParams_"); copyShader_->setUniform("colorTex_", imageUnit.getUnitNumber()); copyShader_->setUniform("depthTex_", imageUnitDepth.getUnitNumber()); renderQuad(); copyShader_->deactivate(); LGL_ERROR; // 2. render overlay over copied input image (using compositor shader) // check, if overlay dims are greater zero bool dimensionsValid = ( (usePixelCoordinates_.getValue() && tgt::hand(tgt::greaterThan(overlayDimensions_.get(), tgt::ivec2(0)))) || (!usePixelCoordinates_.getValue() && tgt::hand(tgt::greaterThan(overlayDimensionsRelative_.get(), tgt::vec2(0.f)))) ); if (renderOverlay_.get() && /*overlayInport_.isReady() &&*/ dimensionsValid) { // bind overlay to tex unit TextureUnit overlayUnit; tgt::Texture* overlayTex = privatePort_.getColorTexture();//overlayInport_.getColorTexture(); tgtAssert(overlayTex, "No overlay texture"); overlayUnit.activate(); overlayTex->bind(); program_->activate(); setGlobalShaderParameters(program_); // image texture parameters imageInport_.setTextureParameters(program_, "textureParameters0_"); program_->setUniform("colorTex0_", imageUnit.getUnitNumber()); program_->setUniform("depthTex0_", imageUnitDepth.getUnitNumber()); program_->setUniform("colorTex1_", overlayUnit.getUnitNumber()); //program_->setUniform("weightingFactor_", 1.f-overlayOpacity_.get()); // determine overlay dimensions and bottom-left in float pixel coords tgt::vec2 outportDim = tgt::vec2(outport_.getSize()); tgt::vec2 overlayDim, overlayBL; if (usePixelCoordinates_.getValue()) { overlayDim = tgt::vec2(overlayDimensions_.get()); overlayBL = tgt::vec2(overlayBottomLeft_.get()); } else { overlayDim = overlayDimensionsRelative_.get() * outportDim; overlayBL = overlayBottomLeftRelative_.get() * outportDim; } // overlay texture matrix mapping from normalized frag coords (outport) to overlay tex coords tgt::mat4 overlayTexCoordMatrix = tgt::mat4::identity; overlayTexCoordMatrix *= tgt::mat4::createScale(tgt::vec3(outportDim / overlayDim, 0.f)); overlayTexCoordMatrix *= tgt::mat4::createTranslation(-tgt::vec3(overlayBL / outportDim, 1.f)); // overlay texture parameters bool oldIgnoreError = program_->getIgnoreUniformLocationError(); program_->setIgnoreUniformLocationError(true); program_->setUniform("textureParameters1_.dimensions_", overlayDim); program_->setUniform("textureParameters1_.dimensionsRCP_", tgt::vec2(1.f) / overlayDim); program_->setUniform("textureParameters1_.matrix_", overlayTexCoordMatrix); program_->setIgnoreUniformLocationError(oldIgnoreError); LGL_ERROR; // render overlay at specified position and size tgt::vec2 bl = 2.f*overlayBL / outportDim - 1.f; tgt::vec2 dim = 2.f*overlayDim / outportDim; glDepthFunc(GL_ALWAYS); glBegin(GL_QUADS); glVertex2f(bl.x, bl.y); glVertex2f(bl.x + dim.x, bl.y); glVertex2f(bl.x + dim.x, bl.y + dim.y); glVertex2f(bl.x, bl.y + dim.y); glEnd(); glDepthFunc(GL_LESS); program_->deactivate(); LGL_ERROR; } outport_.deactivateTarget(); TextureUnit::setZeroUnit(); LGL_ERROR; }
inline void glTexCoord( const GLfloat & s ) { glTexCoord1f( s ); }
// Called to draw scene void RenderScene(void) { GLfloat x,y,z, angle; static GLubyte image[8][4] = { {0x3f, 0x00, 0x3f, 0x80}, // 진보라 {0x7f, 0x00, 0x7f, 0x80}, // 보라 {0xbf, 0x00, 0xbf, 0x80}, // 남색 {0x00, 0x00, 0xff, 0x80}, // 파랑 {0x00, 0xff, 0x00, 0x80}, // 그린 {0xff, 0xff, 0x00, 0x80}, // 노랑 {0xff, 0x7f, 0x00, 0x80}, // 오렌지 {0xff, 0x00, 0x00, 0x80} // 빨강 }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage1D(GL_TEXTURE_1D,0,4,8,0,GL_RGBA,GL_UNSIGNED_BYTE,image); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glDisable(GL_TEXTURE_1D); glEnable(GL_DEPTH_TEST); glPushMatrix(); //glRotatef(10.0f,0.0f,1.0,0.0f); glTranslatef(0.0f,-40.0f,-100.0f); glColor3f(0.0f,0.8f,0.0f); glBegin(GL_POLYGON); for(angle = 0.0; angle < (2.0*GL_PI) ; angle += (0.03125 *GL_PI)) { x = 200.0f *cos(angle); z = 200.0 * sin(angle); glVertex3f (x,0.0f,z); } glEnd(); glEnable(GL_TEXTURE_1D); glBegin(GL_QUAD_STRIP); for( angle =0.0f; angle <= GL_PI ; angle +=(0.03125 *GL_PI)) { x= 50.0f *cos(angle); y= 50.0f *sin(angle); z = -50.0f; glTexCoord1f(0.0f); glVertex3f(x,y,z); x= 55.0f*cos(angle); y= 55.0f*sin(angle); z= -50.0f; glTexCoord1f(0.7f); glVertex3f(x,y,z); } glEnd(); glPopMatrix(); glutSwapBuffers(); }
void GFXSystem::fillPoly(float *buffer, int numPoint, unsigned char color, uint8 polyType) { int i; switch(polyType) { case 0: { // flat: glColor4ub(g_driver->_palette[color*3], g_driver->_palette[color*3+1], g_driver->_palette[color*3+2], 255); glBegin(GL_POLYGON); for(i = 0; i < numPoint; i++) { glVertex3f(buffer[0], buffer[1], buffer[2]); buffer += 3; } glEnd(); break; } case 1: { // dither (pierre) float *readList; GLdouble textureX = 0; GLdouble textureY = 0; GLdouble textureZ = 0; GLdouble modelMatrix[16]; GLdouble projMatrix[16]; GLint viewMatrix[4]; glBindTexture(GL_TEXTURE_2D, ditherTexture); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); glColor4ub(g_driver->_palette[color*3], g_driver->_palette[color*3+1], g_driver->_palette[color*3+2], 255); readList = (float *)buffer; glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); glGetIntegerv(GL_VIEWPORT, viewMatrix); glBegin(GL_POLYGON); for(i = 0; i < numPoint; i++) { float X = *(readList++); float Y = *(readList++); float Z = *(readList++); //gluProject ( X , Y, -Z , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); glTexCoord2f(X * 200, Y * 200); glVertex3f(X, Y, Z); } glEnd(); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, 0); break; } case 2: { // trans glColor4ub(g_driver->_palette[color*3], g_driver->_palette[color*3+1], g_driver->_palette[color*3+2], 128); glBegin(GL_POLYGON); for(i = 0; i < numPoint; i++) { glVertex3f(buffer[0], buffer[1], buffer[2]); buffer += 3; } glEnd(); break; /* float z1; float z2; float z3; float z4; GLdouble textureX = 0; GLdouble textureY = 0; GLdouble textureZ = 0; GLdouble modelMatrix[16]; GLdouble projMatrix[16]; GLint viewMatrix[4]; glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); glGetIntegerv(GL_VIEWPORT, viewMatrix); ASSERT(numPoint == 3 || numPoint == 4); quadTable[positionInQuadTable].x1 = buffer[0]; quadTable[positionInQuadTable].y1 = buffer[1]; quadTable[positionInQuadTable].z1 = buffer[2]; gluProject ( buffer[0] , buffer[1] , buffer[2] , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); z1 = textureZ; quadTable[positionInQuadTable].x2 = buffer[3]; quadTable[positionInQuadTable].y2 = buffer[4]; quadTable[positionInQuadTable].z2 = buffer[5]; gluProject ( buffer[3] , buffer[4] , buffer[5] , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); z2 = textureZ; quadTable[positionInQuadTable].x3 = buffer[6]; quadTable[positionInQuadTable].y3 = buffer[7]; quadTable[positionInQuadTable].z3 = buffer[8]; gluProject ( buffer[6] , buffer[7] , buffer[8] , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); z3 = textureZ; if(numPoint == 4) { quadTable[positionInQuadTable].x4 = buffer[9]; quadTable[positionInQuadTable].y4 = buffer[10]; quadTable[positionInQuadTable].z4 = buffer[11]; gluProject ( buffer[9] , buffer[10] , buffer[11] , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); z4 = textureZ; } quadTable[positionInQuadTable].color = color; quadTable[positionInQuadTable].transparency = 128; quadTable[positionInQuadTable].numPoint = numPoint; quadTable[positionInQuadTable].sorted = false; quadTable[positionInQuadTable].depth = z1 + z2 + z3; if(numPoint == 4) quadTable[positionInQuadTable].depth += z4; quadTable[positionInQuadTable].depth/=numPoint; /* if(buffer[5] > quadTable[positionInQuadTable].depth) quadTable[positionInQuadTable].depth = (int)buffer[5]; if(buffer[8] > quadTable[positionInQuadTable].depth) quadTable[positionInQuadTable].depth = (int)buffer[8]; if(numPoint == 4) if(buffer[11] > quadTable[positionInQuadTable].depth) quadTable[positionInQuadTable].depth = (int)buffer[11]; */ //positionInQuadTable++; break; } default: case 4: { // marbre int numColorToGo; float *readList = (float *)buffer; int maxY = 0; int minY = 10000; GLdouble textureX = 0; GLdouble textureY = 0; GLdouble textureZ = 0; GLdouble modelMatrix[16]; GLdouble projMatrix[16]; GLint viewMatrix[4]; float colorStep; float colorf; glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); glGetIntegerv(GL_VIEWPORT, viewMatrix); for(i = 0; i < numPoint; i++) { float X = *(readList++); float Y = *(readList++); float Z = *(readList++); textureX = X; textureY = Y; textureZ = Z; /// gluProject ( X , Y , Z , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); if(textureY > maxY) maxY = (int)textureY; if(textureY < minY) minY = (int)textureY; } numColorToGo = 0xF - (color & 0xF); colorStep = numColorToGo / (float)abs(maxY - minY); colorf = 0; readList = (float *)buffer; glColor4ub(255, 255, 255, 255); glBindTexture(GL_TEXTURE_2D, gouraudTexture); glBegin(GL_POLYGON); for(i = 0; i < numPoint; i++) { float X = *(readList++); float Y = *(readList++); float Z = *(readList++); //gluProject ( X , Y , Z , modelMatrix , projMatrix , viewMatrix , &textureX , &textureY , &textureZ ); textureX = X; textureY = Y; textureZ = Z; colorf = (float)(color + (colorStep * (textureY - minY))); if(colorf > color + numColorToGo) colorf = (float)(color + numColorToGo); glTexCoord1f(colorf / 256); // glColor3ub(palette[colorf*3],palette[colorf*3+1],palette[colorf*3+2]); glVertex3f(X, Y, Z); } glEnd(); glBindTexture(GL_TEXTURE_2D, 0); break; } } }
GLvoid NEHE37::DrawGLScene(){ float TmpShade; MATRIX37 TmpMatrix; VECTOR37 TmpVector, TmpNormal; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Check To See If We Want Anti-Aliased Lines if(outlineSmooth){ glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_LINE_SMOOTH); } else{ glDisable (GL_LINE_SMOOTH); } glTranslatef (0.0f, 0.0f, -2.0f); glRotatef (modelAngle, 0.0f, 1.0f, 0.0f); glGetFloatv (GL_MODELVIEW_MATRIX, TmpMatrix.Data); // Cel-Shading Code glEnable (GL_TEXTURE_1D); glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); glColor3f (1.0f, 1.0f, 1.0f); glBegin (GL_TRIANGLES); for (int i = 0; i < polyNum; i++){ for (int j = 0; j < 3; j++){ TmpNormal.X = polyData[i].Verts[j].Nor.X; TmpNormal.Y = polyData[i].Verts[j].Nor.Y; TmpNormal.Z = polyData[i].Verts[j].Nor.Z; RotateVector (TmpMatrix, TmpNormal, TmpVector); Normalize (TmpVector); TmpShade = DotProduct (TmpVector, lightAngle); if (TmpShade < 0.0f) TmpShade = 0.0f; glTexCoord1f (TmpShade); glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDisable (GL_TEXTURE_1D); // Outline Code if (outlineDraw){ glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA ,GL_ONE_MINUS_SRC_ALPHA); glPolygonMode (GL_BACK, GL_LINE); glLineWidth (outlineWidth); glCullFace (GL_FRONT); glDepthFunc (GL_LEQUAL); glColor3fv (&outlineColor[0]); glBegin (GL_TRIANGLES); for (int i = 0; i < polyNum; i++){ for (int j = 0; j < 3; j++){ glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDepthFunc (GL_LESS); glCullFace (GL_BACK); glPolygonMode (GL_BACK, GL_FILL); glDisable (GL_BLEND); } /* //draw FPS text glDisable(GL_TEXTURE_2D); glLoadIdentity (); glTranslatef(0.0f,0.0f,-1.0f); glColor3f(0.8f,0.8f,0.8f);//set text color computeFPS(); Utils::drawText(-0.54f,-0.4f, GLUT_BITMAP_HELVETICA_12, FPSstr); glEnable(GL_TEXTURE_2D); */ glutSwapBuffers(); //handle key input if(specialKeys[GLUT_KEY_DOWN]){ outlineWidth--; specialKeys[GLUT_KEY_DOWN] = FALSE; } if(specialKeys[GLUT_KEY_UP]){ outlineWidth++; specialKeys[GLUT_KEY_UP] = FALSE; } if(keys[' ']){ modelRotate = !modelRotate; // Toggle Model Rotation On/Off keys[' '] = false; } if(keys['1']){ outlineDraw = !outlineDraw; // Toggle Outline Drawing On/Off keys['1'] = false; } if(keys['2']){ outlineSmooth = !outlineSmooth; // Toggle Anti-Aliasing On/Off keys['2'] = false; } if (modelRotate) modelAngle += 1.0f; }
void Display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_1D, textures[0]); glBegin(GL_QUADS); glTexCoord1f(0.0f); glVertex2f(-1.0f, 0.4f); glTexCoord1f(0.0f); glVertex2f(-1.0f, 0.9f); glTexCoord1f(1.0f); glVertex2f( 1.0f, 0.9f); glTexCoord1f(1.0f); glVertex2f( 1.0f, 0.4f); glEnd(); glBindTexture(GL_TEXTURE_1D, textures[1]); glBegin(GL_QUADS); glTexCoord1f(0.0f); glVertex2f(-1.0f, -0.25f); glTexCoord1f(0.0f); glVertex2f(-1.0f, 0.25f); glTexCoord1f(1.0f); glVertex2f(1.0f, 0.25f); glTexCoord1f(1.0f); glVertex2f( 1.0f, -0.25f); glEnd(); glBindTexture(GL_TEXTURE_1D, textures[2]); glBegin(GL_QUADS); glTexCoord1f(0.0f); glVertex2f(-1.0f, -0.9f); glTexCoord1f(0.0f); glVertex2f(-1.0f, -0.4f); glTexCoord1f(1.0f); glVertex2f(1.0f, -0.4f); glTexCoord1f(1.0f); glVertex2f(1.0f, -0.9f); glEnd(); glutSwapBuffers(); }
void drawGLScene(void) { int i, j; float TmpShade; MATRIX TmpMatrix; VECTOR TmpVector, TmpNormal; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); if (True == outlineSmooth) { glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_LINE_SMOOTH); } else glDisable (GL_LINE_SMOOTH); glTranslatef (0.0f, 0.0f, -2.0f); glRotatef (modelAngle, 0.0f, 1.0f, 0.0f); glGetFloatv (GL_MODELVIEW_MATRIX, TmpMatrix.Data); glEnable (GL_TEXTURE_1D); glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); glColor3f (1.0f, 1.0f, 1.0f); glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { TmpNormal.X = polyData[i].Verts[j].Nor.X; TmpNormal.Y = polyData[i].Verts[j].Nor.Y; TmpNormal.Z = polyData[i].Verts[j].Nor.Z; RotateVector (&TmpMatrix, &TmpNormal, &TmpVector); Normalize (&TmpVector); TmpShade = DotProduct (&TmpVector,&lightAngle); if (TmpShade < 0.0f) TmpShade = 0.0f; glTexCoord1f (TmpShade); glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDisable (GL_TEXTURE_1D); if (True == outlineDraw) { glEnable (GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glPolygonMode (GL_BACK, GL_LINE); glLineWidth (outlineWidth); glCullFace (GL_FRONT); glDepthFunc (GL_LEQUAL); glColor3fv (&outlineColor[0]); glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { glVertex3fv (&polyData[i].Verts[j].Pos.X); } } glEnd (); glDepthFunc (GL_LESS); glCullFace (GL_BACK); glPolygonMode (GL_BACK, GL_FILL); glDisable (GL_BLEND); } }
static void drawSample( int x, int y, int w, int h, int texgenenabled, int coordnr ) { char buf[255]; glViewport( x, y, w, h ); glScissor( x, y, w, h ); glClearColor( 0.1, 0.1, 0.1, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); begin2D( w, h ); if (texgenenabled == 2) { sprintf( buf, "TexCoord%df", coordnr); drawString( buf, 10, h - 15, labelInfoColor ); sprintf( buf, "texgen enabled for %s coordinate(s)", coordnr == 2 ? "S" : "S/T"); drawString( buf, 10, 5, labelInfoColor ); } else if (texgenenabled == 0) { sprintf( buf, "TexCoord%df", coordnr); drawString( buf, 10, h - 15, labelInfoColor ); drawString( "no texgen", 10, 5, labelInfoColor ); } else if (texgenenabled == 1) { drawString( "no TexCoord", 10, h - 15, labelInfoColor ); sprintf( buf, "texgen enabled for %s coordinate(s)", coordnr == 2 ? "S/T" : (coordnr == 3 ? "S/T/R" : "S/T/R/Q")); drawString( buf, 10, 5, labelInfoColor ); } end2D(); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); loadTexture( textureWidth, textureHeight ); if ( drawTextured ) { glEnable( GL_TEXTURE_2D ); } glDisable( GL_TEXTURE_GEN_S ); glDisable( GL_TEXTURE_GEN_T ); glDisable( GL_TEXTURE_GEN_R ); glDisable( GL_TEXTURE_GEN_Q ); glMatrixMode( GL_TEXTURE ); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); switch (coordnr) { case 2: switch (texgenenabled) { case 0: glBegin( GL_QUADS ); glTexCoord2f( 0.0, 0.0 ); glVertex2f( -0.8, -0.8 ); glTexCoord2f( 1.0, 0.0 ); glVertex2f( 0.8, -0.8 ); glTexCoord2f( 1.0, 1.0 ); glVertex2f( 0.8, 0.8 ); glTexCoord2f( 0.0, 1.0 ); glVertex2f( -0.8, 0.8 ); glEnd(); break; case 1: glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS3); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT3); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); /* Issue a texcoord here to be sure Q isn't left over from a * previous sample. */ glTexCoord1f( 0.0 ); glBegin( GL_QUADS ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.0, 1.0 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; case 2: /* make sure that texgen T and non-texgen S coordinate are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS1); glTexGenfv(GL_T, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glBegin( GL_QUADS ); /* use z coordinate to get correct texgen values... */ glTexCoord2f( 0.0, 0.0 ); glVertex3f( -0.8, -0.8, 0.8 ); glTexCoord2f( 0.0, 0.0 ); glVertex3f( 0.8, -0.8, 0.2 ); glTexCoord2f( 0.0, 1.0 ); glVertex3f( 0.8, 0.8, 0.2 ); glTexCoord2f( 0.0, 1.0 ); glVertex3f( -0.8, 0.8, 0.8 ); glEnd(); break; } break; case 3: glMatrixMode( GL_TEXTURE ); glLoadMatrixf( texmat_swap_rq ); glMatrixMode( GL_MODELVIEW ); glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); switch (texgenenabled) { case 0: glBegin( GL_QUADS ); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 0.0 ); glTexCoord3f( 0.5, 0.0, 0.5 ); glVertex2f( 1.0, 0.0 ); glTexCoord3f( 0.5, 0.5, 0.5 ); glVertex2f( 1.0, 1.0 ); glTexCoord3f( 0.0, 0.5, 0.5 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; case 1: glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glTexCoord1f( 0.0 ); /* to make sure Q is 1.0 */ glBegin( GL_QUADS ); glVertex3f( 0.0, 0.0, 0.5 ); glVertex3f( 1.0, 0.0, 0.5 ); glVertex3f( 1.0, 1.0, 0.5 ); glVertex3f( 0.0, 1.0, 0.5 ); glEnd(); break; case 2: /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glBegin( GL_QUADS ); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 0.0); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 1.0, 0.0); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 1.0, 1.0); glTexCoord3f( 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 1.0); glEnd(); break; } break; case 4: switch (texgenenabled) { case 0: glBegin( GL_QUADS ); /* don't need r coordinate but still setting it I'm mean */ glTexCoord4f( 0.0, 0.0, 0.0, 0.5 ); glVertex2f( -0.8, -0.8 ); glTexCoord4f( 0.5, 0.0, 0.2, 0.5 ); glVertex2f( 0.8, -0.8 ); glTexCoord4f( 0.5, 0.5, 0.5, 0.5 ); glVertex2f( 0.8, 0.8 ); glTexCoord4f( 0.0, 0.5, 0.5, 0.5 ); glVertex2f( -0.8, 0.8 ); glEnd(); break; case 1: glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, ObjPlaneR); glTexGenfv(GL_Q, GL_OBJECT_PLANE, ObjPlaneQ); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glEnable( GL_TEXTURE_GEN_Q ); glBegin( GL_QUADS ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.0, 1.0 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; case 2: glTranslatef( -0.8, -0.8, 0.0 ); glScalef( 1.6, 1.6, 1.0 ); /* make sure that texgen R/Q and non-texgen S/T coordinates are wrong */ glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv(GL_S, GL_OBJECT_PLANE, ObjPlaneS2); glTexGenfv(GL_T, GL_OBJECT_PLANE, ObjPlaneT2); glTexGenfv(GL_R, GL_OBJECT_PLANE, nullPlane); glTexGenfv(GL_Q, GL_OBJECT_PLANE, nullPlane); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glBegin( GL_QUADS ); glTexCoord4f( 0.0, 0.0, 0.0, 0.5 ); glVertex2f( 0.0, 0.0 ); glTexCoord4f( 0.0, 0.0, 0.2, 0.5 ); glVertex2f( 1.0, 0.0 ); glTexCoord4f( 0.0, 0.0, 0.5, 0.5 ); glVertex2f( 1.0, 1.0 ); glTexCoord4f( 0.0, 0.0, 0.75, 0.5 ); glVertex2f( 0.0, 1.0 ); glEnd(); break; } break; } glPopMatrix(); glDisable( GL_TEXTURE_2D ); }
void gl_drawwin() { int i; NGNoTransp = 0; // Set this value to 1 within the appropriate // video mode if you want to add a custom // transparency routine or hardware // transparency. This only works if // the value of newengen is equal to 1. // (see ProcessTransparencies in newgfx16.asm // for ZSNES' current transparency code) UpdateVFrame(); if (curblank != 0) return; if (BilinearFilter) { glfilters = GL_LINEAR; if (GUIOn2 && !FilteredGUI) glfilters = GL_NEAREST; } else { glfilters = GL_NEAREST; } if (En2xSaI && SurfaceX != 256) { /* We have to use copy640x480x16bwin for 2xSaI */ AddEndBytes = 0; NumBytesPerLine = 1024; WinVidMemStart = (void *) glvidbuffer; copy640x480x16bwin(); /* Display 4 256x256 quads for the 512x448 buffer */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glfilters); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glfilters); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); /* Upper left quad */ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 512); glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glvidbuffer); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, (224.0 / 256.0)); glVertex3f(0.0f, 0.0f, -1.0f); glTexCoord2f(0.0f, (224.0 / 256.0)); glVertex3f(-1.0f, 0.0f, -1.0f); glEnd(); /* Upper right quad */ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 512); glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glvidbuffer + 256); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, -1.0f); glTexCoord2f(1.0f, (224.0 / 256.0)); glVertex3f(1.0f, 0.0f, -1.0f); glTexCoord2f(0.0f, (224.0 / 256.0)); glVertex3f(0.0f, 0.0f, -1.0f); glEnd(); /* Lower left quad */ glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 512); glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glvidbuffer + 512 * 224); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, (224.0 / 256.0)); glVertex3f(0.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, (224.0 / 256.0)); glVertex3f(-1.0f, -1.0f, -1.0f); glEnd(); /* Lower right quad */ glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glvidbuffer + 512 * 224 + 256); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 0.0f, -1.0f); glTexCoord2f(1.0f, (224.0 / 256.0)); glVertex3f(1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, (224.0 / 256.0)); glVertex3f(0.0f, -1.0f, -1.0f); glEnd(); } else { /* * This code splits the hires/lores portions up, and draws * them with gl_drawspan */ int lasthires, lasthires_line = 0; gltexture256 = gltexture512 = 0; lasthires = SpecialLine[1]; for (i = 1; i < 222; i++) { if (SpecialLine[i + 1]) { if (lasthires) continue; gl_drawspan(lasthires, lasthires_line, i); lasthires = SpecialLine[i + 1]; lasthires_line = i; } else { if (!lasthires) continue; gl_drawspan(lasthires, lasthires_line, i); lasthires = SpecialLine[i + 1]; lasthires_line = i; } } gl_drawspan(lasthires, lasthires_line, i); /* * This is here rather than right outside this if because the * GUI doesn't allow scanlines to be selected while filters are * on.. There is no technical reason they can't be on while * filters are on, however. Feel free to change the GUI, and * move this outside the if (En2xSaI) {}, if you do. */ if (scanlines) { glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_1D, gltextures[3]); glColor4f(1.0f, 1.0f, 1.0f, scanlines == 1 ? 1.0f : (scanlines == 2 ? 0.25f : 0.50f)); for (i = 0; i < SurfaceY; i += 256) { glBegin(GL_QUADS); glTexCoord1f(0.0f); glVertex3f(-1.0f, (SurfaceY - i * 2.0) / SurfaceY, -1.0f); glTexCoord1f(0.0f); glVertex3f(1.0f, (SurfaceY - i * 2.0) / SurfaceY, -1.0f); glTexCoord1f(1.0f); glVertex3f(1.0f, (SurfaceY - (i + 256) * 2.0) / SurfaceY, -1.0f); glTexCoord1f(1.0f); glVertex3f(-1.0f, (SurfaceY - (i + 256) * 2.0) / SurfaceY, -1.0f); glEnd(); } glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); } } SDL_GL_SwapBuffers(); }
M(void, glTexCoord1f, jfloat s) { glTexCoord1f(s); }
void TransFuncTexturePainter::paint() { // ensure that no shader is active while painting if (GpuCaps.areShadersSupported()) tgt::Shader::deactivate(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); float inc = 0.1f; // paint checkerboard for (int i = 0 ; i < 10 ; ++i) { glBegin(GL_QUADS); // Front Face if (i % 2) glColor3f(0.6f, 0.6f, 0.6f); else glColor3f(1.f, 1.f, 1.f); glVertex3f( i * inc, 0.0f, -0.5f); // Bottom Left glVertex3f((i + 1) * inc, 0.0f, -0.5f); // Bottom Right glVertex3f((i + 1) * inc, 0.5f, -0.5f); // Top Right glVertex3f( i * inc, 0.5f, -0.5f); // Top Left glEnd(); glBegin(GL_QUADS); // Front Face if (i % 2) glColor3f(1.f, 1.f, 1.f); else glColor3f(0.6f, 0.6f, 0.6f); glVertex3f( i * inc, 0.5f, -0.5f); // Bottom Left glVertex3f((i + 1) * inc, 0.5f, -0.5f); // Bottom Right glVertex3f((i + 1) * inc, 1.0f, -0.5f); // Top Right glVertex3f( i * inc, 1.0f, -0.5f); // Top Left glEnd(); } // paint transfer function if (tf_) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_1D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE); tf_->bind(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glBegin(GL_QUADS); glColor4f(1.f, 1.f, 1.f, 1.f); // Bottom Left glTexCoord1f(0.f); glVertex3f(0.f, 0.f, -0.5f); // Bottom Right glTexCoord1f(1.f); glVertex3f(1.f, 0.f, -0.5f); // Top Right glTexCoord1f(1.f); glVertex3f(1.f, 1.f, -0.5f); // Top Left glTexCoord1f(0.f); glVertex3f(0.f, 1.f, -0.5f); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_1D); } }
template< > inline void glTexCoord1< float > ( float s ) { glTexCoord1f(s); };
void Redraw(void) { GLfloat x, y, z, th; static GLubyte roygbiv_image[8][3] = { { 0x3f, 0x00, 0x3f }, /* 深蓝紫色 */ { 0x7f, 0x00, 0x7f }, /* 蓝紫色 */ { 0xbf, 0x00, 0xbf }, /* 靛蓝 */ { 0x00, 0x00, 0xff }, /* 蓝色 */ { 0x00, 0xff, 0x00 }, /* 绿色 */ { 0xff, 0xff, 0x00 }, /* 黄色 */ { 0xff, 0x7f, 0x00 }, /* 橙色 */ { 0xff, 0x00, 0x00 } /* 红色 */ }; glClearColor(0.5, 0.5, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //定义纹理放大和缩小函数均为GL_LINEAR //表示使用最靠近使用纹理象素的四个纹素的加权均值 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //定义一维纹理:颜色分量为RGB, //宽度为8,边界为0,使用无符号整数 glTexImage1D(GL_TEXTURE_1D, 0, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, roygbiv_image); //定义纹理环境参数:仅使用纹理图像 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); /* 绘制地面*/ glDisable(GL_TEXTURE_1D); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glPushMatrix(); glRotatef(10.0, 0.0, 1.0, 0.0); glTranslatef(0.0, -40.0, -100.0); glColor3f(0.0, 0.8, 0.0); glBegin(GL_POLYGON); for (th = 0.0; th < (2.0 * M_PI); th += (0.03125 * M_PI)) { x = cos(th) * 200.0; z = sin(th) * 200.0; glVertex3f(x, 0.0, z); } glEnd(); /* 绘制彩虹 */ glEnable(GL_TEXTURE_1D); glBegin(GL_QUAD_STRIP); for (th = 0.0; th <= M_PI; th += (0.03125 * M_PI)) { x = cos(th) * 50.0; y = sin(th) * 50.0; z = -50.0; glTexCoord1f(0.0); glVertex3f(x, y, z); x = cos(th) * 55.0; y = sin(th) * 55.0; z = -50.0; glTexCoord1f(1.0); glVertex3f(x, y, z); } glEnd(); glPopMatrix(); glFlush(); }
/* The main drawing function. */ void DrawGLScene() { int i, j; // Looping Variables float TmpShade; // Temporary Shader Value MATRIX TmpMatrix; // Temporary MATRIX Structure VECTOR TmpVector, TmpNormal; // Temporary VECTOR Structures glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Buffers glLoadIdentity (); // Reset The Matrix // Check To See If We Want Anti-Aliased Lines if (outlineSmooth) { glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); // Use The Good Calculations glEnable (GL_LINE_SMOOTH); // Enable Anti-Aliasing } else { // We Don't Want Smooth Lines // Disable Anti-Aliasing glDisable (GL_LINE_SMOOTH); } // Move 2 Units Away From The Screen glTranslatef (0.0f, 0.0f, -2.0f); // Rotate The Model On It's Y-Axis glRotatef (modelAngle, 0.0f, 1.0f, 0.0f); InitGL(800, 600); // Get The Generated Matrix glGetFloatv(GL_MODELVIEW_MATRIX, TmpMatrix.Data); // Cel-Shading Code // // Enable 1D Texturing glDisable (GL_TEXTURE_3D); glDisable (GL_TEXTURE_2D); glEnable (GL_TEXTURE_1D); // Bind to current texture glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); // Set colour of model glColor3f (0.0, 0.0, 0.0); glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { TmpNormal.X = polyData[i].Verts[j].Nor.X; // Fill Up The TmpNormal Structure With TmpNormal.Y = polyData[i].Verts[j].Nor.Y; // The Current Vertices' Normal Values TmpNormal.Z = polyData[i].Verts[j].Nor.Z; RotateVector (TmpMatrix, TmpNormal, TmpVector); // Rotate This By The Matrix Normalize (TmpVector); // Normalize The New Normal TmpShade = DotProduct (TmpVector, lightAngle); // Calculate The Shade Value if (TmpShade < 0.0f) TmpShade = 0.0f; // Clamp The Value to 0 If Negative glTexCoord1f (TmpShade); // Set The Texture Co-ordinate As The Shade Value glVertex3fv(&polyData[i].Verts[j].Pos.X); // Send The Vertex Position } } glEnd(); glDisable (GL_TEXTURE_1D); // Disable 1D Textures // Outline Code // // Check To See If We Want To Draw The Outline if (outlineDraw) { glEnable (GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonMode (GL_BACK, GL_LINE); // Draw Backfacing Polygons As Wireframes glLineWidth (outlineWidth); // Set The Line Width glCullFace (GL_FRONT); // Don't Draw Any Front-Facing Polygons glDepthFunc (GL_LEQUAL); // Change The Depth Mode glColor3fv (&outlineColor[0]); // Set The Outline Color glBegin (GL_TRIANGLES); for (i = 0; i < polyNum; i++) { for (j = 0; j < 3; j++) { glVertex3fv (&polyData[i].Verts[j].Pos.X); // Send The Vertex Position } } glEnd(); glDepthFunc (GL_LESS); // Reset The Depth-Testing Mode glCullFace (GL_BACK); // Reset The Face To Be Culled glPolygonMode (GL_BACK, GL_FILL); // Reset Back-Facing Polygon Drawing Mode glDisable (GL_BLEND); // Disable Blending } // since this is double buffered, swap the buffers to display what just got drawn. //glutSwapBuffers(); // Check To See If Rotation Is Enabled if (modelRotate) { modelAngle += 2.0f; } }