|
|

楼主 |
发表于 2008-5-23 22:42:00
|
显示全部楼层
Re:OpenGL程序在ATI卡上运行很快,在NVIDIA卡上超慢,什么原
- //用GL渲染文字, x、y为文字的屏幕的光栅位置;xspacing为文字间距
- void CHKText::RenderTextByGL(int x, int y, int xspacing, int yspacing, int color, int fontSize, wchar_t* text)
- {
- if(fontSize > 0)
- {
- //如果字体大小改变
- if(fontSize != this->size)
- {
- //销毁当前文字模型
- this->Destory();
- //改变字体大小
- if(this->ChangeSize(fontSize))
- {
- //创建新的文字模型
- this->CreateText(text);
- }
- }
- }
-
- wchar_t* p = text;
- int row = 0;
- int span = 0;
- WORDINFO* word = NULL;
- //获取文字颜色
- float rs = (color & 0x000000FF) * 0.003922f;
- float gs = ((color & 0x0000FF00)>>8) * 0.003922f;
- float bs = ((color & 0x00FF0000)>>16) * 0.003922f;
- float as = ((color & 0xFF000000)>>24) * 0.003922f;
- glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_PIXEL_MODE_BIT);
-
- //设置像素存储模式
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- //设置光栅像素的颜色及不透明度
- glPixelTransferf(GL_RED_SCALE, rs);
- glPixelTransferf(GL_GREEN_SCALE, gs);
- glPixelTransferf(GL_BLUE_SCALE, bs);
- glPixelTransferf(GL_ALPHA_SCALE, as);
-
- //开启混合并设置混合方式
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- //遍历文字数组
- while( p && (*p != (wchar_t)'\0') )
- {
- //通过文字的unicode码获取文字的模型信息
- word = GetWord(*p);
- //如果该文字存在
- if(word != NULL)
- {
- //设置光栅位置并绘制文字
- glWindowPos2i(x+span, y-word->top);
- span += word->left + xspacing;
- glDrawPixels(word->width, word->height, GL_RGBA, GL_UNSIGNED_BYTE, word->bitmap);
- }
- p++;
- }
- glPopAttrib();
- } //end RenderTextByGL
复制代码 |
|