void UnitDragger::initContext(GLContextData& contextData) const { /* Create a context data item and add it to the context data: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Render the influence model: */ glNewList(dataItem->displayListId,GL_COMPILE); glPushAttrib(GL_COLOR_BUFFER_BIT|GL_ENABLE_BIT|GL_LINE_BIT|GL_POLYGON_BIT); glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glDepthMask(GL_FALSE); glLineWidth(1.0f); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glColor4f(0.0f,1.0f,0.0f,0.33f); glDrawSphereIcosahedron(1.0f,5); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glColor4f(0.1f,0.5f,0.1f,0.33f); glDrawSphereIcosahedron(1.0f,5); glDepthMask(GL_TRUE); glPopAttrib(); glEndList(); }
void WalkNavigationToolFactory::initContext(GLContextData& contextData) const { if(drawMovementCircles) { /* Create a new data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create the tool model display list: */ glNewList(dataItem->modelListId,GL_COMPILE); /* Set up OpenGL state: */ glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glLineWidth(1.0f); glColor(movementCircleColor); /* Create a coordinate system for the floor plane: */ Vector y=centerViewDirection; Vector x=Geometry::cross(y,floorPlane.getNormal()); x.normalize(); /* Draw the inner circle: */ glBegin(GL_LINE_LOOP); for(int i=0;i<64;++i) { Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(64); glVertex(Point::origin-x*(Math::sin(angle)*innerRadius)+y*(Math::cos(angle)*innerRadius)); } glEnd(); /* Draw the outer circle: */ glBegin(GL_LINE_LOOP); for(int i=0;i<64;++i) { Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(64); glVertex(Point::origin-x*(Math::sin(angle)*outerRadius)+y*(Math::cos(angle)*outerRadius)); } glEnd(); /* Draw the inner angle: */ glBegin(GL_LINE_STRIP); glVertex(Point::origin-x*(Math::sin(innerAngle)*innerRadius)+y*(Math::cos(innerAngle)*innerRadius)); glVertex(Point::origin); glVertex(Point::origin-x*(Math::sin(-innerAngle)*innerRadius)+y*(Math::cos(-innerAngle)*innerRadius)); glEnd(); /* Draw the outer angle: */ glBegin(GL_LINE_STRIP); glVertex(Point::origin-x*(Math::sin(outerAngle)*outerRadius)+y*(Math::cos(outerAngle)*outerRadius)); glVertex(Point::origin); glVertex(Point::origin-x*(Math::sin(-outerAngle)*outerRadius)+y*(Math::cos(-outerAngle)*outerRadius)); glEnd(); /* Reset OpenGL state: */ glPopAttrib(); glEndList(); } }
void ParticleSprayerTool::initContext(GLContextData& contextData) const { DataItem* dataItem=new DataItem; contextData.addDataItem(this, dataItem); BlueRedColorMap colorMap; // calculate and store point positions const unsigned int SIZE=16; Vrui::Point pts[SIZE]; const float ToRadians=M_PI / 180.0; // randomly distribute points within volume of a cone srand(10000); for (unsigned int i=0; i < SIZE; i++) { float fi=(float) rand() / (float) RAND_MAX * 30.0; float theta=(float) rand() / (float) RAND_MAX * 360.0; float r=(float) rand() / (float) RAND_MAX * 2.0; pts[i][0]=r * sin(fi * ToRadians) * cos(theta * ToRadians); pts[i][1]=r * sin(fi * ToRadians) * sin(theta * ToRadians); pts[i][2]=r * cos(fi * ToRadians); } // create new display list glNewList(dataItem->displayListId, GL_COMPILE); // save current attribute state glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); for (unsigned int i=0; i < SIZE; i++) { // color points based on "height" int index=(int) (pts[i][2] / 2.0 * 255.0); const float* color=colorMap.getColor(index); GLMaterial sphereMaterial(GLMaterial::Color(color[0], color[1], color[2]), GLMaterial::Color(1.0, 1.0, 1.0, 1.0), 80.0); glMaterial(GLMaterialEnums::FRONT_AND_BACK, sphereMaterial); // base size on "height" as well float radius=0.03 + 0.08 * (float) pts[i][2] / 2.0; glPushMatrix(); glTranslatef(pts[i][0], pts[i][1], pts[i][2]); glDrawSphereIcosahedron(radius, 8); glPopMatrix(); } // restore previous attribute state glPopAttrib(); glEndList(); }
void TripleChannelRaycaster::initContext(GLContextData& contextData) const { /* Create a new data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Initialize the data item: */ initDataItem(dataItem); try { /* Load and compile the vertex program: */ std::string vertexShaderName=VISUALIZER_SHADERDIR; vertexShaderName.append("/TripleChannelRaycaster.vs"); dataItem->shader.compileVertexShader(vertexShaderName.c_str()); std::string fragmentShaderName=VISUALIZER_SHADERDIR; fragmentShaderName.append("/TripleChannelRaycaster.fs"); dataItem->shader.compileFragmentShader(fragmentShaderName.c_str()); dataItem->shader.linkShader(); /* Initialize the raycasting shader: */ initShader(dataItem); } catch(std::runtime_error err) { /* Print an error message, but continue: */ std::cerr<<"TripleChannelRaycaster::initContext: Caught exception "<<err.what()<<std::endl; } }
/* * initContext * * parameter glContextData - GLContextData& */ void SliceWidget::initContext(GLContextData& glContextData) const { DataItem * dataItem = new DataItem(); glContextData.addDataItem(this, dataItem); dataItem->textureNonPowerOfTwo = GLARBTextureNonPowerOfTwo::isSupported(); //glGetIntegerv(GL_MAX_2D_TEXTURE_SIZE, &dataItem->maximum2DTextureSize); initializeSliceTexture(dataItem); } // end initContext()
void SixDofWithScaleNavigationToolFactory::initContext(GLContextData& contextData) const { /* Create a new data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create the tool model display list: */ glNewList(dataItem->modelListId,GL_COMPILE); /* Set up OpenGL state: */ glPushAttrib(GL_ENABLE_BIT|GL_POLYGON_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glLineWidth(1.0f); glColor3f(1.0f,1.0f,1.0f); /* Render a sphere of radius scaleDeviceDistance around the scaling device's position: */ glDrawSphereIcosahedron(scaleDeviceDistance,3); /* Render the scaling direction: */ glLineWidth(3.0f); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINES); Point pos=Point::origin; glVertex(pos); pos+=deviceScaleDirection*scaleDeviceDistance*Scalar(1.25); glVertex(pos); glEnd(); /* Reset OpenGL state: */ glPopAttrib(); glEndList(); }
void HelloVrui::initContext(GLContextData& contextData) const { /* Create a new context data item: */ DataItem* dataItem=new DataItem(); contextData.addDataItem(this,dataItem); this->renWin->AddRenderer(this->ren.GetPointer()); vtkNew<vtkPolyDataMapper> mapper; vtkNew<vtkPolyDataMapper> mapper1; vtkNew<vtkActor> actor; vtkNew<vtkActor> actor1; actor->SetMapper(mapper.GetPointer()); actor1->SetMapper(mapper1.GetPointer()); this->ren->AddActor(actor.GetPointer()); this->ren->AddActor(actor1.GetPointer()); this->ren->AutomaticLightCreationOff(); this->ren->PreserveColorBufferOn(); this->ren->PreserveDepthBufferOn(); this->ren->RemoveAllLights(); vtkNew<vtkLight> light; light->SetLightTypeToSceneLight(); // light->SetPositional(true); // vtkNew<vtkLightActor> lightActor; // lightActor->SetLight(light.GetPointer()); this->ren->AddLight(light.GetPointer()); // this->ren->AddViewProp(lightActor.GetPointer()); vtkNew<vtkCubeSource> ss; vtkNew<vtkSphereSource> ss1; ss1->SetRadius(1.5); ss1->SetCenter(2,0,1); mapper->SetInputConnection(ss->GetOutputPort()); mapper1->SetInputConnection(ss1->GetOutputPort()); }
void DotSpreaderTool::initContext(GLContextData& contextData) const { DataItem* dataItem=new DataItem; contextData.addDataItem(this, dataItem); // calculate and store positions of particles const int SIZE=12; float points[SIZE][3]; srand(1234); for (int i=0; i < SIZE; i++) { points[i][0]=0.8 - 1.6 * ((float) rand() / (float) RAND_MAX); points[i][1]=0.8 - 1.6 * ((float) rand() / (float) RAND_MAX); points[i][2]=0.8 - 1.6 * ((float) rand() / (float) RAND_MAX); } // create a new display list glNewList(dataItem->displayListId, GL_COMPILE); GLUquadric* quadric=gluNewQuadric(); // save current attribute state glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT); // draw sphere wireframe sphere glDisable(GL_LIGHTING); gluQuadricDrawStyle(quadric, GLU_LINE); glColor3f(0.0f, 0.8f, 1.0f); gluSphere(quadric, 1.0, 8, 12); // set up materials/lighting for particles glEnable(GL_LIGHTING); GLMaterial sphereMaterial(GLMaterial::Color(1.0, 0.0, 0.0, 1.0), GLMaterial::Color(1.0, 1.0, 1.0, 1.0), 80.0); glMaterial(GLMaterialEnums::FRONT_AND_BACK, sphereMaterial); // draw randomly positioned spheres for (int i=0; i < SIZE; i++) { glPushMatrix(); glTranslatef(points[i][0], points[i][1], points[i][2]); glDrawSphereIcosahedron(0.1, 8); glPopMatrix(); } gluDeleteQuadric(quadric); // restore previous attribute state glPopAttrib(); glEndList(); }
inline void IndexedTriangleSet<VertexParam>::initContext( GLContextData& contextData) const { /* Create a new context data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); }
inline void MultiPolyline<VertexParam>::initContext( GLContextData& contextData) const { /* Create a new context data item: */ DataItem* dataItem=new DataItem(numPolylines); contextData.addDataItem(this,dataItem); }
void GLPolylineTube::initContext(GLContextData& contextData) const { /* Create a data item and store it in the context data: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Upload the current version of the tube geometry to OpenGL: */ updateTubeVertices(dataItem); updateTubeIndices(dataItem); }
/* * initContext * * parameter glContextData - GLContextData& */ void Scene::initContext(GLContextData& glContextData) const { DataItem* dataItem = new DataItem(); glContextData.addDataItem(this, dataItem); dataItem->shaderManager = new ShaderManager(); if (!dataItem->shaderManager->initializeGLSL()) { std::cout << "Error: Can't initialize GLSL" << std::endl; } dataItem->pointeShaderObject = dataItem->shaderManager->loadFromMemory(vertexShader, fragmentShader); initialize1DColorMap(dataItem); } // end initContext()
void GLFont::String::initContext(GLContextData& contextData) const { /* Create a data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Upload the string's texture image: */ glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId); font->uploadStringTexture(string,stringWidth,textureWidth); glBindTexture(GL_TEXTURE_2D,0); }
void SphereNode::initContext(GLContextData& contextData) const { /* Create a data item and store it in the context: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create the sphere's display list: */ glNewList(dataItem->displayListId,GL_COMPILE); glDrawSphereMercatorWithTexture(radius,45,90); glEndList(); }
void VRMeshEditor::initContext(GLContextData& contextData) const { /* Create a new context entry: */ contextData.addDataItem(this,new DataItem); #if 0 /* Disable all viewers' headlights: */ for(int i=0; i<Vrui::getNumViewers(); ++i) Vrui::getViewer(i)->setHeadlightState(false); #endif }
void Doom3TextureManager::initContext(GLContextData& contextData) const { /* Create a context data item and store it in the OpenGL context: */ DataItem* dataItem=new DataItem(numTextures); contextData.addDataItem(this,dataItem); /* Upload all textures: */ TextureUploader tu(*this,dataItem); imageTree.forEachLeaf(tu); /* Unbind all texture objects: */ glBindTexture(GL_TEXTURE_2D,0); }
void ConeNode::initContext(GLContextData& contextData) const { /* Create a data item and store it in the context: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create the cone's display list: */ glNewList(dataItem->displayListId,GL_COMPILE); float h2=height*0.5f; int numQuads=32; if(bottom) { /* Draw the cone's bottom cap: */ glBegin(GL_POLYGON); glNormal3f(0.0f,-1.0f,0.0f); for(int i=numQuads-1;i>=0;--i) { float angle=2.0f*Math::Constants<float>::pi*float(i)/float(numQuads); float c=Math::cos(angle); float s=Math::sin(angle); glTexCoord2f(-s*0.5f+0.5f,-c*0.5f+0.5f); glVertex3f(-s*bottomRadius,-h2,-c*bottomRadius); } glEnd(); } if(side) { /* Draw the cone's side: */ float normalScale=1.0f/Math::sqrt(height*height+bottomRadius*bottomRadius); glBegin(GL_QUAD_STRIP); for(int i=0;i<numQuads;++i) { float angle=2.0f*Math::Constants<float>::pi*float(i)/float(numQuads); float texS=float(i)/float(numQuads); float c=Math::cos(angle); float s=Math::sin(angle); glNormal3f(-s*height*normalScale,bottomRadius*normalScale,-c*height*normalScale); glTexCoord2f(texS,1.0f); glVertex3f(0.0f, h2,0.0f); glTexCoord2f(texS,0.0f); glVertex3f(-s*bottomRadius,-h2,-c*bottomRadius); } glNormal3f(0.0f,bottomRadius*normalScale,-height*normalScale); glTexCoord2f(1.0f,1.0f); glVertex3f(0.0f,h2,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(0.0f,-h2,-bottomRadius); glEnd(); } glEndList(); }
void VruiSoundTest::initContext(GLContextData& contextData) const { /* Create a new context data item: */ GLDataItem* dataItem=new GLDataItem; contextData.addDataItem(this,dataItem); /* Create a display list to render a sphere: */ glNewList(dataItem->displayListId,GL_COMPILE); /* Draw the sphere: */ glDrawSphereIcosahedron(1.0f,10); glEndList(); }
void GridEditor::initContext(GLContextData& contextData) const { /* Create a context data item and store it in the context: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create the influence sphere display list: */ glNewList(dataItem->influenceSphereDisplayListId,GL_COMPILE); glDisable(GL_CULL_FACE); glLineWidth(1.0f); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glColor4f(1.0f,1.0f,0.0f,0.5f); glDrawSphereIcosahedron(1.0,5); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glColor4f(0.5f,0.5f,0.1f,0.333f); glDrawSphereIcosahedron(1.0,5); glEndList(); /* Create the domain box display list: */ Point min=Point::origin; Point max; for(int i=0;i<3;++i) max[i]=float(grid->getNumVertices(i)-1)*grid->getCellSize(i); Vrui::Color fgColor=Vrui::getBackgroundColor(); for(int i=0;i<3;++i) fgColor[i]=1.0f-fgColor[i]; glNewList(dataItem->domainBoxDisplayListId,GL_COMPILE); glColor(fgColor); glBegin(GL_LINE_STRIP); glVertex(min[0],min[1],min[2]); glVertex(max[0],min[1],min[2]); glVertex(max[0],max[1],min[2]); glVertex(min[0],max[1],min[2]); glVertex(min[0],min[1],min[2]); glVertex(min[0],min[1],max[2]); glVertex(max[0],min[1],max[2]); glVertex(max[0],max[1],max[2]); glVertex(min[0],max[1],max[2]); glVertex(min[0],min[1],max[2]); glEnd(); glBegin(GL_LINES); glVertex(max[0],min[1],min[2]); glVertex(max[0],min[1],max[2]); glVertex(max[0],max[1],min[2]); glVertex(max[0],max[1],max[2]); glVertex(min[0],max[1],min[2]); glVertex(min[0],max[1],max[2]); glEnd(); glEndList(); }
void VideoViewer::initContext(GLContextData& contextData) const { DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Check whether non-power-of-two-dimension textures are supported: */ dataItem->haveNpotdt=GLARBTextureNonPowerOfTwo::isSupported(); if(dataItem->haveNpotdt) GLARBTextureNonPowerOfTwo::initExtension(); /* Calculate the texture coordinate rectangle: */ unsigned int texSize[2]; if(dataItem->haveNpotdt) { for(int i=0; i<2; ++i) texSize[i]=videoFormat.size[i]; } else { /* Find the next larger power-of-two texture size: */ for(int i=0; i<2; ++i) for(texSize[i]=1U; texSize[i]<videoFormat.size[i]; texSize[i]<<=1) ; } /* Calculate texture coordinates to map the (padded) texture onto the geometry: */ for(int i=0; i<2; ++i) { dataItem->texMin[i]=0.0f; dataItem->texMax[i]=GLfloat(videoFormat.size[i])/GLfloat(texSize[i]); } /* Bind the texture object: */ glBindTexture(GL_TEXTURE_2D,dataItem->videoTextureId); /* Initialize basic texture settings: */ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); /* Upload the initial texture image: */ videoFrames.getLockedValue().glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,!dataItem->haveNpotdt); dataItem->videoTextureVersion=videoFrameVersion; /* Protect the texture object: */ glBindTexture(GL_TEXTURE_2D,0); }
inline void DataSetRenderer<DataSetWrapperParam>::initContext( GLContextData& contextData) const { /* Create a new context data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Upload the initial data set rendering into the display list: */ glNewList(dataItem->displayListId,GL_COMPILE_AND_EXECUTE); dsr.glRenderAction(contextData); glEndList(); dataItem->displayVersion=displayVersion; }
void CylinderRenderer::initContext(GLContextData& contextData) const { /* Create context data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create model display list: */ glNewList(dataItem->displayListId,GL_COMPILE); /* Render cylinder: */ Scalar hradius=Cylinder::radius/Scalar(3); glNormal3f(0.0f,0.0f,-1.0); glBegin(GL_POLYGON); for(int i=7;i>=0;--i) { Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(8); Scalar c=Math::cos(angle); Scalar s=Math::sin(angle); glVertex(Point(c*hradius,s*hradius,-Cylinder::radius)); } glEnd(); glBegin(GL_QUAD_STRIP); for(int i=0;i<=8;++i) { Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i%8)/Scalar(8); Scalar c=Math::cos(angle); Scalar s=Math::sin(angle); glNormal(Vector(c,s,Scalar(0))); glVertex(Point(c*hradius,s*hradius,Cylinder::radius)); glVertex(Point(c*hradius,s*hradius,-Cylinder::radius)); } glEnd(); glNormal3f(0.0f,0.0f,1.0); glBegin(GL_POLYGON); for(int i=0;i<8;++i) { Scalar angle=Scalar(2)*Math::Constants<Scalar>::pi*Scalar(i)/Scalar(8); Scalar c=Math::cos(angle); Scalar s=Math::sin(angle); glVertex(Point(c*hradius,s*hradius,Cylinder::radius)); } glEnd(); /* Finish model display list: */ glEndList(); }
void JediTool::initContext(GLContextData& contextData) const { DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Upload the light saber image as a 2D texture: */ glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); lightsaberImage.glTexImage2D(GL_TEXTURE_2D,0,GL_RGB); glBindTexture(GL_TEXTURE_2D,0); }
void FTTextGLObject::initContext(GLContextData& contextData) const { FTTextGLObjectDataItem* data = new FTTextGLObjectDataItem(); FTFontStyleNode* fs = text->fontStyle.getValue().getPointer(); contextData.addDataItem(this, data); FTBBox bbox = fs->ftfont->BBox(text->string.getValue(0).c_str()); text->boundingBox = Box(Point(bbox.Lower().X(), bbox.Lower().Y(), bbox.Lower().Z()), Point(bbox.Upper().X(), bbox.Upper().Y(), bbox.Upper().Z())); // Dodgy float width = (bbox.Upper().X() - bbox.Lower().X()); switch (fs->justify_major) { case FTFontStyle::FIRST: case FTFontStyle::BEGIN: data->offset = 0; break; case FTFontStyle::MIDDLE: data->offset = -width/2.0; break; case FTFontStyle::END: data->offset = -width; break; default: data->offset = 0; break; } }
void MouseCursorFaker::initContext(GLContextData& contextData) const { /* Create and store a data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Upload the cursor image as a 2D texture: */ glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); cursorImage.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,true); glBindTexture(GL_TEXTURE_2D,0); }
void ImageViewer::initContext(GLContextData& contextData) const { DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Check whether non-power-of-two-dimension textures are supported: */ bool haveNpotdt=GLARBTextureNonPowerOfTwo::isSupported(); if(haveNpotdt) GLARBTextureNonPowerOfTwo::initExtension(); /* Calculate the texture coordinate rectangle: */ unsigned int texSize[2]; if(haveNpotdt) { for(int i=0;i<2;++i) texSize[i]=image.getSize(i); } else { for(int i=0;i<2;++i) for(texSize[i]=1U;texSize[i]<image.getSize(i);texSize[i]<<=1) ; } for(int i=0;i<2;++i) { dataItem->texMin[i]=0.0f; dataItem->texMax[i]=GLfloat(image.getSize(i))/GLfloat(texSize[i]); } /* Bind the texture object: */ glBindTexture(GL_TEXTURE_2D,dataItem->imageTextureId); /* Initialize basic texture settings: */ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); /* Upload the texture image: */ image.glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,!haveNpotdt); /* Protect the texture object: */ glBindTexture(GL_TEXTURE_2D,0); }
void Viewer::initContext(GLContextData& contextData) const { // create data item and add it to the context data DTS::DataItem* dataItem=new DTS::DataItem; contextData.addDataItem(this, dataItem); // get point sprite image std::string directory(RESOURCEDIR); Images::RGBImage spriteTexture=Images::readImageFile((directory+"/particle.png").c_str()); // initialize texture parameters glBindTexture(GL_TEXTURE_2D, dataItem->spriteTextureObjectId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); spriteTexture.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB); glBindTexture(GL_TEXTURE_2D, 0); }
void TriangleRenderer::initContext(GLContextData& contextData) const { /* Create context data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); /* Create model display list: */ glNewList(dataItem->displayListId,GL_COMPILE); /* Render triangle sides: */ glBegin(GL_QUADS); glNormal(Triangle::renderNormals[0]); glVertex(Triangle::renderVertices[0]); glVertex(Triangle::renderVertices[1]); glVertex(Triangle::renderVertices[4]); glVertex(Triangle::renderVertices[3]); glNormal(Triangle::renderNormals[1]); glVertex(Triangle::renderVertices[1]); glVertex(Triangle::renderVertices[2]); glVertex(Triangle::renderVertices[5]); glVertex(Triangle::renderVertices[4]); glNormal(Triangle::renderNormals[2]); glVertex(Triangle::renderVertices[2]); glVertex(Triangle::renderVertices[0]); glVertex(Triangle::renderVertices[3]); glVertex(Triangle::renderVertices[5]); glEnd(); /* Render triangle caps: */ glBegin(GL_TRIANGLES); glNormal(Triangle::renderNormals[3]); glVertex(Triangle::renderVertices[0]); glVertex(Triangle::renderVertices[2]); glVertex(Triangle::renderVertices[1]); glNormal(Triangle::renderNormals[4]); glVertex(Triangle::renderVertices[3]); glVertex(Triangle::renderVertices[4]); glVertex(Triangle::renderVertices[5]); glEnd(); /* Finish model display list: */ glEndList(); }
void Doom3Model::initContext(GLContextData& contextData) const { /* Create a new context data item: */ DataItem* dataItem=new DataItem; contextData.addDataItem(this,dataItem); if(dataItem->hasVertexBufferExtension) { /* Upload all vertices into the vertex buffer: */ glBindBufferARB(GL_ARRAY_BUFFER_ARB,dataItem->vertexBufferId); glBufferDataARB(GL_ARRAY_BUFFER_ARB,vertices.size()*sizeof(Vertex),&vertices[0],GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB,0); /* Upload all vertex indices into the index buffer: */ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,dataItem->indexBufferId); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,vertexIndices.size()*sizeof(GLuint),&vertexIndices[0],GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0); } }
void TextNode::initContext(GLContextData& contextData) const { /* Create a data item and store it in the context: */ DataItem* dataItem=new DataItem(string.size()); contextData.addDataItem(this,dataItem); /* Upload texture images for all strings: */ const GLFont* font=dynamic_cast<const FontStyleNode*>(fontStyle.getPointer())->font; GLFont::Color background(0.0f,0.0f,0.0f,0.0f); GLFont::Color foreground(1.0f,1.0f,1.0f,1.0f); for(size_t i=0; i<string.size(); ++i) { glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectIds[i]); font->uploadStringTexture(string[i].c_str(),background,foreground); } /* Protect the texture objects: */ glBindTexture(GL_TEXTURE_2D,0); }