bool CGLImageData::LoadTexture(const char *filename) { if (!LoadBMP(filename)) if(!LoadPNG(filename)) { sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load image->"); return false; } else { if (!MakeTexture()) { sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load texture in video adapter."); return false; } } else { if(!MakeRGBA()) { sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load texture."); return false; } if (!MakeTexture()) { sLog(DEFAULT_LOG_NAME, LOG_WARNING_EV, "Can't load texture in video memory."); return false; } } { delete [] data; data = NULL; } return true; }
const BYTE *FMultiPatchTexture::GetColumn (unsigned int column, const Span **spans_out) { if (bRedirect) { return Parts->Texture->GetColumn (column, spans_out); } if (Pixels == NULL) { MakeTexture (); } if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) { column &= WidthMask; } else { column %= Width; } } if (spans_out != NULL) { if (Spans == NULL) { Spans = CreateSpans (Pixels); } *spans_out = Spans[column]; } return Pixels + column*Height; }
const BYTE* FCELTexture::GetColumn(unsigned int column, const Span** spans) { if (m_pixels == NULL) { MakeTexture(); } if (DWORD(column) >= DWORD(Width)) { if (WidthMask + 1 == Width) { column &= WidthMask; } else { column %= Width; } } if (NULL != spans) { if (NULL == m_spans) { m_spans = CreateSpans(m_pixels); } *spans = m_spans[column]; } return m_pixels + column * Height; }
const uint8_t *FPNGTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) { column &= WidthMask; } else { column %= Width; } } if (spans_out != NULL) { if (Spans == NULL) { Spans = CreateSpans (Pixels); } *spans_out = Spans[column]; } return Pixels + column*Height; }
const BYTE *FWarpTexture::GetColumn (unsigned int column, const Span **spans_out) { DWORD time = r_FrameTime; if (Pixels == NULL || time != GenTime) { MakeTexture (time); } if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) { column &= WidthMask; } else { column %= Width; } } if (spans_out != NULL) { if (Spans == NULL) { Spans = CreateSpans (Pixels); } *spans_out = Spans[column]; } return Pixels + column*Height; }
/** ** Make font bitmap. */ void CFont::MakeFontColorTextures() const { if (!FontColorGraphics[this].empty()) { // already loaded return; } const CGraphic &g = *this->G; SDL_Surface *s = g.Surface; for (FontColorMap::iterator it = FontColors.begin(); it != FontColors.end(); ++it) { CFontColor *fc = it->second; CGraphic *newg = FontColorGraphics[this][fc] = new CGraphic; newg->Width = g.Width; newg->Height = g.Height; newg->NumFrames = g.NumFrames; newg->GraphicWidth = g.GraphicWidth; newg->GraphicHeight = g.GraphicHeight; newg->Surface = g.Surface; SDL_LockSurface(s); for (int j = 0; j < MaxFontColors; ++j) { s->format->palette->colors[j] = fc->Colors[j]; } SDL_UnlockSurface(s); MakeTexture(newg); } }
static void Init(void) { const char *version; (void) MakeTexture; (void) ramp4; (void) ramp2; version = (const char *) glGetString(GL_VERSION); if (version[0] != '2' || version[1] != '.') { printf("This program requires OpenGL 2.x, found %s\n", version); exit(1); } glClearColor(0.3f, 0.3f, 0.3f, 0.0f); printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #if 0 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); #elif 0 MakeTexture(); #else MakeMipmap(); #endif }
const BYTE *FIMGZTexture::GetPixels () { if (Pixels == NULL) { MakeTexture (); } return Pixels; }
const BYTE *FHealthBar::GetPixels () { if (NeedRefresh) { MakeTexture (); } return Pixels; }
const uint8_t *FPNGTexture::GetPixels () { if (Pixels == NULL) { MakeTexture (); } return Pixels; }
const BYTE *FFontChar2::GetPixels () { if (Pixels == NULL) { MakeTexture (); } return Pixels; }
const uint8_t *FCanvasTexture::GetPixels () { bNeedsUpdate = true; if (Canvas == NULL) { MakeTexture (); } return Pixels; }
const BYTE* FCELTexture::GetPixels() { if (NULL == m_pixels) { MakeTexture(); } return m_pixels; }
const BYTE *FFontChar1::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } BaseTexture->GetColumn(column, spans_out); return Pixels + column*Height; }
const BYTE *FWarpTexture::GetPixels () { DWORD time = r_FrameTime; if (Pixels == NULL || time != GenTime) { MakeTexture (time); } return Pixels; }
const BYTE *FMultiPatchTexture::GetPixels () { if (bRedirect) { return Parts->Texture->GetPixels (); } if (Pixels == NULL) { MakeTexture (); } return Pixels; }
void draw_flurry(HDC *hDC, HGLRC *hRC) { static int first = 1; static double oldFrameTime = -1; double newFrameTime; double deltaFrameTime = 0; double brite; GLfloat alpha; global_info_t *global = flurry_info; flurry_info_t *flurry; newFrameTime = currentTime(); if (oldFrameTime == -1) { /* special case the first frame -- clear to black */ alpha = 1.0; } else { /* framerate clamping taken care of by timer */ deltaFrameTime = newFrameTime - oldFrameTime; alpha = 5.0 * deltaFrameTime; } oldFrameTime = newFrameTime; if (alpha > 0.2) alpha = 0.2; if (!global->glx_context) return; if (first) { MakeTexture(); first = 0; } glDrawBuffer(GL_BACK); wglMakeCurrent(*hDC, *hRC); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0, 0.0, 0.0, alpha); glRectd(0, 0, global->sys_glWidth, global->sys_glHeight); brite = pow(deltaFrameTime, 0.75) * 10; for (flurry = global->flurry; flurry; flurry = flurry->next) { GLRenderScene(global, flurry, brite * flurry->briteFactor); } glFinish(); SwapBuffers(*hDC); }
void IrisViewport::SetInitData(float x, float y, float width, float height){ this->rect = new IrisRect(x, y, width, height); MakeBuffer(); MakeTexture(); this->Device->CreateOffscreenPlainSurface(this->GetWidth(), this->GetHeight(), D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &this->renderSurface, NULL); ModuleIrisGraphics::addViewport(this); ModuleIrisGraphics::sortViewports(); }
void Ball_initialize() { int n_lats = 90; int n_lons = 180; int ii,jj; earthTextureID = MakeTexture(Earth_texture, EARTH_TEXTURE_WIDTH, EARTH_TEXTURE_HEIGHT); if (BallListID == 0) { BallListID = glGenLists(1); glNewList( BallListID, GL_COMPILE); glEnable(GL_LIGHTING); glBindTexture(GL_TEXTURE_2D, earthTextureID); glEnable(GL_TEXTURE_2D); for(ii = 0; ii <= n_lats; ii++) { double lat0 = PI * (-0.5 + (double) (ii - 1) / n_lats); double z0 = sin(lat0); double zr0 = cos(lat0); double lat1 = PI * (-0.5 + (double) ii / n_lats); double z1 = sin(lat1); double zr1 = cos(lat1); glBegin(GL_QUAD_STRIP); for(jj = 0; jj <= n_lons; jj++) { double lon = 2 * PI * (double) (jj - 1) / n_lons; double x = cos(lon); double y = sin(lon); glTexCoord2d( 0.0, 0.0); glNormal3d(x * zr0, y * zr0, z0); glVertex3d(x * zr0, y * zr0, z0); glTexCoord2d( 1.0, 1.0); glNormal3d(x * zr1, y * zr1, z1); glVertex3d(x * zr1, y * zr1, z1); } glEnd(); } glEndList(); } }
const BYTE *FFontChar2::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } if (column >= Width) { column = WidthMask; } if (spans_out != NULL) { *spans_out = Spans[column]; } return Pixels + column*Height; }
const BYTE *FHealthBar::GetColumn (unsigned int column, const Span **spans_out) { if (NeedRefresh) { MakeTexture (); } if (column > 199) { column = 199; } if (spans_out != NULL) { *spans_out = &DummySpan[column >= (unsigned int)VialLevel*2]; } return Pixels + column*2; }
const BYTE *FManaBar::GetColumn (unsigned int column, const Span **spans_out) { if (NeedRefresh) { MakeTexture (); } if (column > 4) { column = 4; } if (spans_out != NULL) { *spans_out = DummySpan; } return Pixels + column*24; }
const BYTE *FAutomapTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } if ((unsigned)column >= (unsigned)Width) { column %= Width; } if (spans_out != NULL) { *spans_out = DummySpan; } return Pixels + column*Height; }
IrisViewport::IrisViewport(float x, float y, float width, float height){ this->rect = new IrisRect(x, y, width, height); this->Device = this->Device = ModuleIrisGraphics::Device; this->visible = true; this->z = 0.0f; this->ox = this->oy = 0.0f; this->tone = new IrisTone(0, 0, 0, 0); this->color = NULL; MakeBuffer(); MakeTexture(); this->Device->CreateOffscreenPlainSurface(this->GetWidth(), this->GetHeight(), D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &this->renderSurface, NULL); ModuleIrisGraphics::addViewport(this); ModuleIrisGraphics::sortViewports(); }
TextureData TexturePool::Create(const char* path, GLenum textureUnit, GLenum sWrap, GLenum tWrap) { //find if the path exists auto iter = m_Textures.find(path); //if it doesnt if (iter == m_Textures.end()) { //create a new texture TextureData data; data.index = MakeTexture(path, &data.width, &data.height, textureUnit, sWrap, tWrap); //add it to the map and return it m_Textures[path] = std::make_pair(data, 1); return data; } else { //increment the reference count and return it ++iter->second.second; return iter->second.first; } }
const BYTE *FFlatTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) { MakeTexture (); } if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) { column &= WidthMask; } else { column %= Width; } } if (spans_out != NULL) { *spans_out = DummySpans; } return Pixels + column*Height; }
const uint8_t *FCanvasTexture::GetColumn (unsigned int column, const Span **spans_out) { bNeedsUpdate = true; if (Canvas == NULL) { MakeTexture (); } if ((unsigned)column >= (unsigned)Width) { if (WidthMask + 1 == Width) { column &= WidthMask; } else { column %= Width; } } if (spans_out != NULL) { *spans_out = DummySpans; } return Pixels + column*Height; }
static void Init(void) { static const char *fragShaderText = "uniform sampler2DShadow shadowTex2D; \n" "uniform sampler2DRectShadow shadowTexRect; \n" "void main() {\n" #if USE_RECT " gl_FragColor = shadow2DRectProj(shadowTexRect, gl_TexCoord[0]); \n" #else " gl_FragColor = shadow2D(shadowTex2D, gl_TexCoord[0].xyz); \n" #endif "}\n"; static const char *vertShaderText = "void main() {\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" " gl_TexCoord[0] = gl_MultiTexCoord0; \n" "}\n"; const char *version; #if USE_RECT if (!glutExtensionSupported("GL_ARB_texture_rectangle")) { printf("This program requires GL_ARB_texture_rectangle\n"); exit(1); } #endif version = (const char *) glGetString(GL_VERSION); if (version[0] != '2' || version[1] != '.') { printf("This program requires OpenGL 2.x, found %s\n", version); exit(1); } printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); fragShader = glCreateShader(GL_FRAGMENT_SHADER); if (FragProgFile) ReadShader(fragShader, FragProgFile); else LoadAndCompileShader(fragShader, fragShaderText); vertShader = glCreateShader(GL_VERTEX_SHADER); if (VertProgFile) ReadShader(vertShader, VertProgFile); else LoadAndCompileShader(vertShader, vertShaderText); program = glCreateProgram(); glAttachShader(program, fragShader); glAttachShader(program, vertShader); glLinkProgram(program); CheckLink(program); glUseProgram(program); uTexture2D = glGetUniformLocation(program, "shadowTex2D"); uTextureRect = glGetUniformLocation(program, "shadowTexRect"); printf("uTexture2D %d uTextureRect %d\n", uTexture2D, uTextureRect); if (uTexture2D >= 0) { glUniform1i(uTexture2D, 0); /* use texture unit 0 */ } if (uTextureRect >= 0) { glUniform1i(uTextureRect, 1); /* use texture unit 0 */ } CheckError(__LINE__); glClearColor(0.3f, 0.3f, 0.3f, 0.0f); glColor3f(1, 1, 1); MakeTexture(); CheckError(__LINE__); }
static void Init(void) { static const char *fragShaderText = "uniform vec4 diffuse;\n" "uniform vec4 specular;\n" "varying vec3 normal;\n" "void main() {\n" " // Compute dot product of light direction and normal vector\n" " float dotProd = max(dot(gl_LightSource[0].position.xyz, \n" " normalize(normal)), 0.0);\n" " // Compute diffuse and specular contributions\n" " gl_FragColor = diffuse * dotProd + specular * pow(dotProd, 20.0);\n" "}\n"; static const char *vertShaderText = "varying vec3 normal;\n" "void main() {\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" " normal = gl_NormalMatrix * gl_Normal;\n" "}\n"; const char *version; version = (const char *) glGetString(GL_VERSION); if (version[0] != '2' || version[1] != '.') { printf("This program requires OpenGL 2.x, found %s\n", version); exit(1); } GetExtensionFuncs(); fragShader = glCreateShader_func(GL_FRAGMENT_SHADER); if (FragProgFile) ReadShader(fragShader, FragProgFile); else LoadAndCompileShader(fragShader, fragShaderText); vertShader = glCreateShader_func(GL_VERTEX_SHADER); if (VertProgFile) ReadShader(vertShader, VertProgFile); else LoadAndCompileShader(vertShader, vertShaderText); program = glCreateProgram_func(); glAttachShader_func(program, fragShader); glAttachShader_func(program, vertShader); glLinkProgram_func(program); CheckLink(program); glUseProgram_func(program); uDiffuse = glGetUniformLocation_func(program, "diffuse"); uSpecular = glGetUniformLocation_func(program, "specular"); uTexture = glGetUniformLocation_func(program, "texture"); printf("DiffusePos %d SpecularPos %d TexturePos %d\n", uDiffuse, uSpecular, uTexture); glUniform4fv_func(uDiffuse, 1, diffuse); glUniform4fv_func(uSpecular, 1, specular); /* assert(glGetError() == 0);*/ glUniform1i_func(uTexture, 2); /* use texture unit 2 */ /*assert(glGetError() == 0);*/ if (CoordAttrib) { int i; glBindAttribLocation_func(program, CoordAttrib, "coord"); i = glGetAttribLocation_func(program, "coord"); assert(i >= 0); if (i != CoordAttrib) { printf("Hmmm, NVIDIA bug?\n"); CoordAttrib = i; } else { printf("Mesa bind attrib: coord = %d\n", i); } } /*assert(glGetError() == 0);*/ glClearColor(0.3f, 0.3f, 0.3f, 0.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20.0f); MakeSphere(); MakeRect(); CurList = SphereList; #if TEXTURE MakeTexture(); #endif printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); printf("Press p to toggle between per-pixel and per-vertex lighting\n"); /* test glGetShaderSource() */ if (0) { GLsizei len = strlen(fragShaderText) + 1; GLsizei lenOut; GLchar *src =(GLchar *) malloc(len * sizeof(GLchar)); glGetShaderSource_func(fragShader, 0, NULL, src); glGetShaderSource_func(fragShader, len, &lenOut, src); assert(len == lenOut + 1); assert(strcmp(src, fragShaderText) == 0); free(src); } assert(glIsProgram_func(program)); assert(glIsShader_func(fragShader)); assert(glIsShader_func(vertShader)); glColor3f(1, 0, 0); /* for testing state vars */ { static GLfloat fc[4] = { 1, 1, 0, 0 }; static GLfloat amb[4] = { 1, 0, 1, 0 }; glFogfv(GL_FOG_COLOR, fc); glLightfv(GL_LIGHT1, GL_AMBIENT, amb); } #if 0 TestFunctions(); #else (void) TestFunctions; #endif }
void Satellite_initialize(void) { FILE fp; capsuleTextureID = MakeTexture(Capsule_texture, CAPSULE_TEXTURE_WIDTH, CAPSULE_TEXTURE_HEIGHT); nozzleTextureID = MakeTexture(Nozzle_texture, NOZZLE_TEXTURE_WIDTH, NOZZLE_TEXTURE_HEIGHT); if (displayListID == 0) { /* Build Display list.*/ double cosine[33]; double sine[33]; double radius1 = 0.254; double station1 = 3.5738; double radius2 = 1.9558; double station2 = 0.8128; double radius3 = 1.9558; double station3 = -3.1242; double radius4 = 0.3048; double station4 = -3.1242; double radius5 = 0.508; double station5 = -3.5560; double radius6 = 1.016; double station6 = -4.8260; double radius7 = 1.27; double station7 = -6.0858; int ii; for(ii=0 ; ii <= 32 ; ii++) { double angle = (PI*2*ii)/32.0; cosine[ii] = cos(angle); sine[ii] = sin(angle); } displayListID = glGenLists(1); glNewList( displayListID, GL_COMPILE); glEnable(GL_LIGHTING); glBindTexture(GL_TEXTURE_2D, capsuleTextureID); glEnable(GL_TEXTURE_2D); glBegin(GL_QUAD_STRIP); for(ii=0 ; ii <= 32 ; ii++) { double t = (double)ii/32.0; glTexCoord2d( 0.0, t); glNormal3d( (station2-station1)/radius2-radius1, sine[ii], cosine[ii]); glVertex3d( station1, sine[ii]*radius1, cosine[ii]*radius1); glTexCoord2d( 1.0, t); glNormal3d( (station2-station1)/radius2-radius1, sine[ii], cosine[ii]); glVertex3d( station2, sine[ii]*radius2, cosine[ii]*radius2); } glEnd(); glDisable(GL_TEXTURE_2D); glBegin(GL_QUAD_STRIP); for(ii=0 ; ii <= 32 ; ii++) { glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station2, sine[ii]*radius2, cosine[ii]*radius2); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station3, sine[ii]*radius3, cosine[ii]*radius3); } glEnd(); glBegin(GL_QUAD_STRIP); for(ii=0 ; ii <= 32 ; ii++) { glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station3, sine[ii]*radius3, cosine[ii]*radius3); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station4, sine[ii]*radius4, cosine[ii]*radius4); } glEnd(); glBegin(GL_QUAD_STRIP); for(ii=0 ; ii <= 32 ; ii++) { glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station4, sine[ii]*radius4, cosine[ii]*radius4); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station5, sine[ii]*radius5, cosine[ii]*radius5); } glEnd(); glEnable(GL_LIGHTING); if (nozzleTextureID != 0) { glBindTexture(GL_TEXTURE_2D, nozzleTextureID); glEnable(GL_TEXTURE_2D); } glBegin(GL_QUAD_STRIP); for(ii=0 ; ii <= 32 ; ii++) { double t = (double)ii/32.0; glTexCoord2d( 0.0, t); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station5, sine[ii]*radius5, cosine[ii]*radius5); glTexCoord2d( 0.5, t); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station6, sine[ii]*radius6, cosine[ii]*radius6); } glEnd(); glBegin(GL_QUAD_STRIP); for(ii=0 ; ii <= 32 ; ii++) { double t = (double)ii/32.0; glTexCoord2d( 0.5, t); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station6, sine[ii]*radius6, cosine[ii]*radius6); glTexCoord2d( 1.0, t); glNormal3d( 0.0, sine[ii], cosine[ii]); glVertex3d( station7, sine[ii]*radius7, cosine[ii]*radius7); } glEnd(); glEndList(); } }