Texture buildTexture(const Rect& r, float textureWidth, float textureHeight, bool useHalfTexel) { Texture ret; ret.uv = getTextureCoordinates(r, textureWidth, textureHeight,true); ret.textureID = 0; ret.dim = Vector2f(r.width(), r.height()); return ret; }
osg::Geometry* TiledMap::createTile(const osg::Vec3& corner, float width, float height, int gid) { osg::Geometry* tile = new osg::Geometry; osg::Vec3Array* coords = new osg::Vec3Array(4); (*coords)[0] = corner; (*coords)[1] = corner+osg::Vec3(width, 0.0, 0.0); (*coords)[2] = corner+osg::Vec3(width, height, 0.0); (*coords)[3] = corner+osg::Vec3(0.0, height, 0.0); tile->setVertexArray(coords); osg::Vec3Array* norms = new osg::Vec3Array(1); (*norms)[0] = osg::Vec3(0.0, 0.0, 1.0); tile->setNormalArray(norms, osg::Array::BIND_OVERALL); osg::Vec2Array* tcoords = getTextureCoordinates(gid); tile->setTexCoordArray(0,tcoords); tile->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); tile->setStateSet(this->state); return tile; }
vec4 getColor(){ if (uRenderingMode == 2){ return vec4(0.0, 0.0, 0.3, 0.5); //x-ray semitransparent light blue colour } int restyle = int(floor(aState[1] + 0.5)); if (restyle > 224){ int index = int (floor(aStyleIndex + 0.5)); vec2 coords = getTextureCoordinates(index, uStyleTextureSize); return texture2D(uStyleSampler, coords); } //return colour based on restyle vec2 coords = getTextureCoordinates(restyle, 15); return texture2D(uStateStyleSampler, coords); }
/*Count texture coordinates rectangle in which the imagePoint transwer to*/ QVector<QPointF> ConverterUV::getTextureRect(QPointF imagePoint) { QVector<QPointF> textureRect = QVector<QPointF>(); for(qreal i = -0.5; i <= 0.5; i++) { for(qreal j = -0.5; j <= 0.5; j++) { textureRect.push_back(getTextureCoordinates(imagePoint + QPointF(i, j))); } } return textureRect; }
vec3 getVertexPosition(){ int index = int (floor(aVertexIndex +0.5)); vec2 coords = getTextureCoordinates(index, uVertexTextureSize); vec3 point = vec3(texture2D(uVertexSampler, coords)); int tIndex = int(floor(aTransformationIndex + 0.5)); if (tIndex != 65535) { tIndex *=4; //get transformation matrix 4x4 and transform the point mat4 transform = mat4( texture2D(uMatrixSampler, getTextureCoordinates(tIndex, uMatrixTextureSize)), texture2D(uMatrixSampler, getTextureCoordinates(tIndex+1, uMatrixTextureSize)), texture2D(uMatrixSampler, getTextureCoordinates(tIndex+2, uMatrixTextureSize)), texture2D(uMatrixSampler, getTextureCoordinates(tIndex+3, uMatrixTextureSize)) ); return vec3(transform * vec4(point, 1.0)); } return point; }
void SDLFontGL::drawTextGL(TextGraphicsInfo_t & graphicsInfo, int nX, int nY, const char * text) { if (!GlyphCache) createTexture(); int fnt = graphicsInfo.font; int fg = graphicsInfo.fg; int bg = graphicsInfo.bg; int blink = graphicsInfo.blink; assert(fnt >= 0 && fnt < nFonts); assert(fg >= 0 && fg < nCols); assert(bg >= 0 && bg < nCols); assert(fnts && cols && GlyphCache); unsigned len = strlen(text); // Ensure we have the needed font/slots: ensureCacheLine(fnt, graphicsInfo.slot1); ensureCacheLine(fnt, graphicsInfo.slot2); const int stride = 12; // GL_TRIANGLE_STRIP 2*6 drawBackground(bg, nX, nY, len); if (blink) return; GLfloat *tex = &texValues[stride*numChars]; GLfloat *vtx = &vtxValues[stride*numChars]; GLfloat *clrs = &colorValues[2*stride*numChars]; numChars += len; float x_scale = ((float)nWidth) / (float)texW; float y_scale = ((float)nHeight) / (float)texH; GLfloat texCopy[] = { 0.0, 0.0, 0.0, y_scale, x_scale, 0.0, 0.0, y_scale, x_scale, 0.0, x_scale, y_scale }; GLfloat vtxCopy[] = { nX, nY, nX, nY + nHeight, nX + nWidth, nY, nX, nY + nHeight, nX + nWidth, nY, nX + nWidth, nY + nHeight }; SDL_Color fgc = cols[fg]; GLfloat colorCopy[] = { ((float)fgc.r)/255.f, ((float)fgc.g)/255.f, ((float)fgc.b)/255.f, 1.f, ((float)fgc.r)/255.f, ((float)fgc.g)/255.f, ((float)fgc.b)/255.f, 1.f, ((float)fgc.r)/255.f, ((float)fgc.g)/255.f, ((float)fgc.b)/255.f, 1.f, ((float)fgc.r)/255.f, ((float)fgc.g)/255.f, ((float)fgc.b)/255.f, 1.f, ((float)fgc.r)/255.f, ((float)fgc.g)/255.f, ((float)fgc.b)/255.f, 1.f, ((float)fgc.r)/255.f, ((float)fgc.g)/255.f, ((float)fgc.b)/255.f, 1.f }; for (unsigned i = 0; i < len; ++i) { // Populate texture coordinates memcpy(&tex[i*stride],texCopy,sizeof(texCopy)); char c = text[i]; int x,y; getTextureCoordinates(graphicsInfo, c, x, y); float x_offset = ((float)x) / texW; float y_offset = ((float)y) / texH; for(unsigned j = 0; j < stride; j += 2) { tex[i*stride+j] += x_offset; tex[i*stride+j+1] += y_offset; } // Populate vertex coordinates memcpy(&vtx[i*stride],vtxCopy,sizeof(vtxCopy)); for(unsigned j = 0; j < stride; j += 2) { vtxCopy[j] += nWidth; } // Populate color coodinates memcpy(&clrs[i*2*stride], colorCopy, sizeof(colorCopy)); } }