int RegistTexMem( unsigned char *ptr, int size ) { // メモリ上の画像ファイルデータからテクスチャ読み込み // (TEXINFのidを返す) // GLuint id; int texid, tsx,tsy,comp; int sx,sy; unsigned char *pImg; unsigned char *pImg2; pImg = stbi_load_from_memory( ptr, size, &tsx, &tsy, &comp, 4 ); id = -1; if ( pImg != NULL ) { sx = Get2N( tsx ); sy = Get2N( tsy ); if (( sx != tsx )||( sy != tsy )) { // Exchange to 2N bitmap char *p; char *p2; int x,y; pImg2 = (unsigned char *)mem_ini( sx * sy * 4 ); p = (char *)pImg; p2 = (char *)pImg2; for(y=0;y<tsy;y++) { #if 0 p2 = (char *)pImg2 + (sx*y*4); for(x=0;x<tsx;x++) { p2[0] = p[0]; p2[1] = p[1]; p2[2] = p[2]; p2[3] = p[3]; p+=4; p2+=4; } #else memcpy( p2, p, tsx*4 ); p+=tsx*4; p2+=sx*4; #endif } mem_bye(pImg); pImg = pImg2; } glGenTextures( 1, &id ); glBindTexture( GL_TEXTURE_2D, id ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, sx, sy, 0, GL_RGBA, GL_UNSIGNED_BYTE, pImg ); mem_bye(pImg); texid = SetTex( -1, TEXMODE_NORMAL, 0, sx, sy, tsx, tsy, id ); Alertf( "Tex:ID%d (%d,%d)(%dx%d)",texid,sx,sy,tsx,tsy ); return texid; } Alertf( "Tex:failed" ); return -1; }
void PlayerViewport::Render(float frameSeconds, const RenderInfo& screenRenderInfo) { const RenderTarget* current = RenderTarget::GetCurrentTarget(); //Render the world. worldRendTarg.EnableDrawingInto(); //TODO: Fix culling. RenderingState(RenderingState::C_NONE).EnableState(); ScreenClearer(true, true, false, Vector4f(1.0f, 0.0f, 1.0f, 0.0f)).ClearScreen(); Vector3f camPos = LevelConstants::Instance.GetPlayerEyePos(Target->Pos, Target->LookDir); Camera cam(camPos, Target->LookDir, Vector3f(0.0f, 0.0f, 1.0f), false); cam.PerspectiveInfo.SetFOVDegrees(Settings::Instance.FOVDegrees); cam.PerspectiveInfo.Width = (float)worldRendTarg.GetWidth(); cam.PerspectiveInfo.Height = (float)worldRendTarg.GetHeight(); cam.PerspectiveInfo.zNear = LevelConstants::Instance.CameraZNear; cam.PerspectiveInfo.zFar = LevelConstants::Instance.CameraZFar; Matrix4f viewM, projM; cam.GetViewTransform(viewM); cam.GetPerspectiveProjection(projM); RenderInfo worldRenderInfo(Lvl.GetTimeSinceGameStart(), &cam, &viewM, &projM); Lvl.Render(frameSeconds, worldRenderInfo); worldRendTarg.DisableDrawingInto(); //Render post-processing. RenderTarget* finalRnd = PostProcessing::Instance.Apply(worldRendColor, worldRendDepth); if (current != 0) { current->EnableDrawingInto(); } else { Viewport(0, 0, World->GetWindow()->getSize().x, World->GetWindow()->getSize().y).Use(); } //Do the final render to the screen. RenderingState(RenderingState::C_NONE).EnableState(); SetTex(finalRnd->GetColorTextures()[0].MTex); GUITexture::Render(frameSeconds, screenRenderInfo); }
int MakeEmptyTex( int width, int height ) { // メッセージ用の空テクスチャを作成する // GLuint id; int texid; int sx,sy; unsigned char *pImg; sx = Get2N( width ); sy = Get2N( height ); glGenTextures( 1, &id ); glBindTexture( GL_TEXTURE_2D, id ); glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, sx, sy, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL ); texid = SetTex( -1, TEXMODE_MES8, 0, sx, sy, width, height, id ); Alertf( "Tex:ID%d (%d,%d) Clear",texid,sx,sy ); return texid; }
void TerrainGenerator::RenderHeightMap() // This Renders The Height Map As Quads { glPushMatrix(); int X = 0, Y = 0; // Create Some Variables To Walk The Array With. int x, y, z; // Create Some Variables For Readability glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue); glTranslatef(-512,-120,-512); if(!g_HeightMap.size()) return; // Make Sure Our Height Data Is Valid glCullFace(GL_BACK); glEnable(GL_CULL_FACE); fVector3d first; fVector3d second; fVector3d third; fVector3d a; fVector3d b; fVector3d n; double l; if(_vboInit) { for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE ) { for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE ) { //calcNormals first.x = X; first.y = Height(X, Y ); first.z = Y; second.x = X; second.y = Height(X, Y + STEP_SIZE); second.z = Y + STEP_SIZE; third.x = X + STEP_SIZE; third.y = Height(X + STEP_SIZE, Y ); third.z = Y; a.x = second.x - first.x; a.y = second.y - first.y; a.z = second.z - first.z; b.x = third.x - first.x; b.y = third.y - first.y; b.z = third.z - first.z; n.x = (a.y * b.z) - (a.z * b.y); n.y = (a.z * b.x) - (a.x * b.z); n.z = (a.x * b.y) - (a.y * b.x); // Normalize (divide by root of dot product) l = sqrt(n.x * n.x + n.y * n.y + n.z * n.z); n.x /= l; n.y /= l; n.z /= l; // Get The (X, Y, Z) Value For The Bottom Left Vertex x = X; y = Height(X, Y ); z = Y; SetTex(1.0f, 1.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); // Get The (X, Y, Z) Value For The Top Left Vertex x = X; y = Height(X, Y + STEP_SIZE ); z = Y + STEP_SIZE ; SetTex(0.0f, 1.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); // Send This Vertex a VBO then To OpenGL To Be Rendered // Get The (X, Y, Z) Value For The Top Right Vertex x = X + STEP_SIZE; y = Height(X + STEP_SIZE, Y + STEP_SIZE ); z = Y + STEP_SIZE ; SetTex(0.0f, 0.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); // Get The (X, Y, Z) Value For The Bottom Right Vertex x = X + STEP_SIZE; y = Height(X + STEP_SIZE, Y ); z = Y; SetTex(1.0f, 0.0f); SetNormal(n.x,n.y,n.z); SetVertice(x,y,z); } } InitVBO(); _vboInit = false; } CreateVBO(); // Render Polygon glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glPopMatrix(); }
int CMQOMaterial::SetParams( int srcno, D3DXVECTOR4 srcsceneamb, char* srcchar, int srcleng ) { //"肌色" col(1.000 0.792 0.651 1.000) dif(0.490) amb(0.540) emi(0.530) spc(0.020) power(0.00) //DbgOut( L"check!!!: mqomat : SetParams : %d, %s, %d\r\n", srcno, srcchar, srcleng ); materialno = srcno; sceneamb = srcsceneamb;//!!!!!!!!!!!!!!!!! char pat[12][20] = { "col(", "dif(", "amb(", "emi(", "spc(", "power(", "tex(", "alpha(", "bump(", "shader(", "vcol(", "\"" //!!!tex, alpha, bumpよりも後でないとだめ。 }; int pos = 0; int stepnum; int ret; while( pos < srcleng ){ while( (pos < srcleng) && ( (*(srcchar + pos) == ' ') || (*(srcchar + pos) == '\t') ) ){ pos++; } int cmp; int patno, patleng; int isfind = 0; for( patno = 0; patno < 12; patno++ ){ if( isfind == 1 ) break; patleng = (int)strlen( pat[patno] ); if( srcleng - pos >= patleng ){ cmp = strncmp( pat[patno], srcchar + pos, patleng ); if( cmp == 0 ){ isfind = 1; switch( patno ){ case 0: ret = SetCol( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 1: ret = SetDif( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 2: ret = SetAmb( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 3: ret = SetEmi( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 4: ret = SetSpc( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 5: ret = SetPower( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 6: ret = SetTex( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 7: ret = SetAlpha( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 8: ret = SetBump( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 9: ret = SetShader( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 10: ret = SetVcolFlag( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; case 11: //DbgOut( L"MQOMaterial : SetParams : SetName %d\r\n", pos ); ret = SetName( srcchar, pos, srcleng, &stepnum ); if( ret ) return ret; break; default: _ASSERT( 0 ); return 1; break; } } } } if( isfind == 1 ){ pos += stepnum; }else{ pos++; } } ret = ConvParamsTo3F(); _ASSERT( !ret ); return 0; }