/** Laed die Bilder Der Image Mask*/
void GraphicPipeline::InitMask() {

	CreateTexture(g_Texture, "CrossHairMask.bmp", 0);	// Load the cross hair mask used for transparency
	CreateTexture(g_Texture, "CrossHair.bmp", 1);

	//hier Bilder laden ,ich weiss ist nicht perfect aber erstmal eine Loesung
}
Exemple #2
0
FTGlyph* FTTextureFontImpl::MakeGlyphImpl(FT_GlyphSlot ftGlyph)
{
    glyphHeight = static_cast<int>(charSize.Height() + 0.5);
    glyphWidth = static_cast<int>(charSize.Width() + 0.5);

    if(glyphHeight < 1) glyphHeight = 1;
    if(glyphWidth < 1) glyphWidth = 1;

    if(textureIDList.empty())
    {
        textureIDList.push_back(CreateTexture());
        xOffset = yOffset = padding;
    }

    if(xOffset > (textureWidth - glyphWidth))
    {
        xOffset = padding;
        yOffset += glyphHeight;

        if(yOffset > (textureHeight - glyphHeight))
        {
            textureIDList.push_back(CreateTexture());
            yOffset = padding;
        }
    }

    FTTextureGlyph* tempGlyph = new FTTextureGlyph(ftGlyph, textureIDList[textureIDList.size() - 1],
                                                    xOffset, yOffset, textureWidth, textureHeight);
    xOffset += static_cast<int>(tempGlyph->BBox().Upper().X() - tempGlyph->BBox().Lower().X() + padding + 0.5);

    --remGlyphs;

    return tempGlyph;
}
void FTextureManager::AddGroup(int wadnum, int ns, int usetype)
{
	int firsttx = Wads.GetFirstLump(wadnum);
	int lasttx = Wads.GetLastLump(wadnum);
	char name[9];

	name[8] = 0;

	// Go from first to last so that ANIMDEFS work as expected. However,
	// to avoid duplicates (and to keep earlier entries from overriding
	// later ones), the texture is only inserted if it is the one returned
	// by doing a check by name in the list of wads.

	for (; firsttx <= lasttx; ++firsttx)
	{
		if (Wads.GetLumpNamespace(firsttx) == ns)
		{
			Wads.GetLumpName (name, firsttx);

			if (Wads.CheckNumForName (name, ns) == firsttx)
			{
				CreateTexture (firsttx, usetype);
			}
			//StartScreen->Progress();
		}
		else if (ns == ns_flats && Wads.GetLumpFlags(firsttx) & LUMPF_MAYBEFLAT)
		{
			if (Wads.CheckNumForName (name, ns) < firsttx)
			{
				CreateTexture (firsttx, usetype);
			}
			//StartScreen->Progress();
		}
	}
}
FTGlyph* FTGLTextureFont::MakeGlyph (unsigned int glyphIndex) {
	FT_GlyphSlot ftGlyph = face.Glyph (glyphIndex, FT_LOAD_NO_HINTING);
	
	if (ftGlyph) {
		glyphHeight = static_cast<int> (charSize.Height());
		glyphWidth = static_cast<int> (charSize.Width());

		if (textureIDList.empty()) {
			textureIDList.push_back (CreateTexture());
			xOffset = yOffset = padding;
		}

		if (xOffset >  (textureWidth - glyphWidth)) {
			xOffset = padding;
			yOffset += glyphHeight;
			if (yOffset >  (textureHeight - glyphHeight)) {
				textureIDList.push_back (CreateTexture());
				yOffset = padding;
			}
		}

		FTTextureGlyph* tempGlyph =
				new FTTextureGlyph (ftGlyph, textureIDList[textureIDList.size() - 1],
				xOffset, yOffset, textureWidth, textureHeight);
		xOffset += static_cast<int> (tempGlyph->BBox().upperX - tempGlyph->BBox().lowerX + padding);

		--remGlyphs;
		return tempGlyph;
	}
	err = face.Error();
	return NULL;
}
Exemple #5
0
	// Inheritance exigences
	void TGBufferCanvas::Init()
	{
		// Drawable data
		m_output.width = m_width; 
		m_output.height = m_height; 

		// Creating the main frame buffer
		m_frameBuffer = CreateFrameBuffer();
		BindFrameBuffer(m_frameBuffer);
		// Creating the textures
		// Memory allocation
		m_output.buffers.resize(5);

		// The abledo buffer
		TTextureInfo& albedo = m_output.buffers[0];
		albedo.name = "albedo";
		albedo.type = TTextureNature::COLOR;
		albedo.offset = 0;
		CreateTexture(albedo, m_width, m_height);
 		BindToFrameBuffer(albedo);

 		// The normal buffer
		TTextureInfo& normal = m_output.buffers[1];
		normal.name = "normal";
		normal.type = TTextureNature::COLOR;
		normal.offset = 1;
		CreateTexture(normal, m_width, m_height);
 		BindToFrameBuffer(normal);

 		// The specular buffer
		TTextureInfo& specular = m_output.buffers[2];
		specular.name = "specular";
		specular.type = TTextureNature::COLOR;
		specular.offset = 2;
		CreateTexture(specular, m_width, m_height);
 		BindToFrameBuffer(specular);

 		// Position Buffer
		TTextureInfo& position = m_output.buffers[3];
		position.name = "position";
		position.type = TTextureNature::COLOR;
		position.offset = 3;
		CreateTexture(position, m_width, m_height);
 		BindToFrameBuffer(position);

 		// Depth buffer
		TTextureInfo& depth = m_output.buffers[4];
		depth.name = "depth";
		depth.type = TTextureNature::DEPTH;
		depth.offset = 4;
		CreateTexture(depth, m_width, m_height);
 		BindToFrameBuffer(depth);
 		// Making sure everything is OK
 		CheckFrameBuffer();
 		UnBindFrameBuffer();
	}
Exemple #6
0
// initialize initializes the general display design coordinator, creates the 
// primitive sets, textures, objects, lights, sounds, cameras, and text items
//
void Design::initialize() {

       // general display design
    //
   Reflectivity redish = Reflectivity(red);
   Reflectivity greenish = Reflectivity(green);
   Reflectivity bluish = Reflectivity(blue);
   Reflectivity whitish = Reflectivity(white);
   setProjection(0.9f, 1.0f, 1000.0f);
   setAmbientLight(1, 1, 1);
   // camera at a distance - in lhs coordinates
    // camera at a distance - in lhs coordinates
   iCamera* camera = CreateCamera();
   camera->translate(0, 190,-500);
   camera->setRadius(17.8f);
   
    lastUpdate = now;	

    hud = CreateHUD(0.72f, 0.01f, 0.27f, 0.99f, CreateTexture(HUD_IMAGE));
    // cameras ----------------------------------------------------------------

   velocitytxt_=CreateText(Rectf(0.05f,0.27f,0.95f,0.37f),hud,L"",TEXT_HEIGHT,TEXT_TYPEFACE,TEXT_LEFT);
   deltatxt_=CreateText(Rectf(0.05f,0.17f,0.95f,0.27f),hud,L"",TEXT_HEIGHT,TEXT_TYPEFACE,TEXT_LEFT);
   positiontxt_=CreateText(Rectf(0.05f,0.38f,0.95f,0.48f),hud,L"",TEXT_HEIGHT,TEXT_TYPEFACE,TEXT_LEFT);

   lasttextupdate=now;

   // game ----------------------------------------------------------------------
   setBackground(CreateTexture(L"farm.png"));
   catcher = CreatePhysicsBox(-40, -5, 0, 40, 5, 0, &bluish, 1, PHYS_Floating, true);
   iAPIWindow* win = getWindow();
   catcher->translate(0, -70, 0);

   truck = CreatePhysicsBox(-100, -2, 0, 100, 2, 0, &redish, 1, PHYS_Floating, true);
   truck->translate(300, -50, 0);

   Reflectivity yellowish = Reflectivity(yellow);

   iPhysics* fallingBox = CreatePhysicsBox(-10, -10, -10, 10, 10, 10, &yellowish, 1, PHYS_Falling, true);
   fallingBox->translate(-350, 350, 0);
   fallingBox->setVelocity(Vector(5, 20, 0));
   fallingBox->addBodyForce(Vector(0, -10, 0));
   fallingBox->setCollision(CreateCSphere(fallingBox, 5));
   objects.insert(objects.end(), fallingBox);

   wchar_t str[MAX_DESC + 1];
   StringCbPrintfW(str, MAX_DESC, L"Score: 0");
   velocitytxt_->set(str);

   StringCbPrintfW(str, MAX_DESC, L"Life left: 5"); 
   deltatxt_->set(str);
}
Exemple #7
0
void KPboardView::InitializeTextures(const std::string &TextureDirectory,
                                     const std::string &TextureName,
                                     unsigned int TextureSize /*=1*/,
                                     bool         Nearest /*=true*/,
                                     bool         always /*=true*/)
{
    // Read Textures from PNG files
    if (TextureSize == 0)
    {
        throw std::invalid_argument("TextureSize must not be zero.");
    }

    if (textureIds[0] == 0)
    {
        glGenTextures(textureIds.size(), textureIds.data());
    }

    for (decltype(textureIds.size()) idx = 0; idx < textureIds.size(); ++idx)
    {
        auto file = TextureDirectory + TextureName +
                    PATHSEPARATORSTRING + textureFiles[idx];

        if (!always && file == textureSources[idx])
        {
            continue;
        }

        if (!CreateTexture(TextureSize, file, Nearest, &textureIds[idx]))
        {
            file = TextureDirectory + textureFiles[idx];

            if (!always && file == textureSources[idx])
            {
                continue;
            }

            if (!CreateTexture(TextureSize, file, Nearest, &textureIds[idx]))
            {
                std::stringstream message;

                message << "*** Error creating texture from image file '"
                        << file << "'";
                throw std::runtime_error(message.str());
            }
        }

        textureSources[idx] = file;
    }
}
Exemple #8
0
void Init(HWND hWnd)
{
    g_hWnd = hWnd;										// Assign the window handle to a global window handle
    GetClientRect(g_hWnd, &g_rRect);					// Assign the windows rectangle to a global RECT
    InitializeOpenGL(g_rRect.right, g_rRect.bottom);	// Init OpenGL with the global rect

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    CreateTexture(g_Texture[0], "Sun.bmp");				// Load "Sun.bmp" into openGL as a texture for the Sun
    CreateTexture(g_Texture[1], "Earth.bmp");			// Load "Earth.bmp" into openGL as a texture for the Earth
    CreateTexture(g_Texture[2], "Pluto.bmp");			// Load "Pluto.bmp" into openGL as a texture for Pluto

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

}
boost::shared_ptr<tTextureCacheItem> tBillboardTextureCache::GetCacheItem(const QPair<long, long>& imageID, bool wantTexture)
{
    boost::shared_ptr<tTextureCacheItem> xItem;

    if (imageID == QPair<long, long>(-1, -1))
    {
    }
    else if( m_Textures.contains(imageID))
    {
        xItem = m_Textures.value(imageID);

        if ( wantTexture == true )
        {
            if(xItem->xTexture == 0)
            {
                if(xItem->image.isNull() == false)
                {
                    CreateTexture( xItem );
                }
            }
        }
    }
    else
    {
        QImage image;
        QSize imagePixelOffset(0, 0);

        QPair<QSize, QImage> results = m_GetImage(imageID);
        imagePixelOffset = results.first;
        image = results.second;

        if(image.isNull() == false)
        {
            xItem.reset( new tTextureCacheItem() );
            xItem->image = image;
            xItem->imagePixelOffset = imagePixelOffset;

            if( wantTexture == true )
            {
                CreateTexture( xItem );
            }

            m_Textures.insert(imageID, xItem);
        }
    }

    return xItem;
}
FTGlyph* FTGLTextureFont::MakeGlyph( unsigned int g)
{
  FT_Glyph* ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING);
  
  if( ftGlyph)
  {
    // Estimate the glyph size size - global bbox
    glyphHeight = ( charSize.Height());
    glyphWidth = ( charSize.Width());
    
    // Is there a current texture
    if( numTextures == 0)
    {
      glTextureID[0] = CreateTexture();
      xOffset = yOffset = padding;
      ++numTextures;
    }
    
    // will it fit in the current texture
    if( xOffset > ( textureWidth - glyphWidth))
    {
      xOffset = padding;
      yOffset += glyphHeight;
      
      if( yOffset > ( textureHeight - glyphHeight))
      {
        // no - make a new texture
        glTextureID[numTextures] = CreateTexture();
        yOffset = padding;
        ++numTextures;
      }
    }
    
    // yes - load the glyph
    FTTextureGlyph* tempGlyph = new FTTextureGlyph( *ftGlyph, glTextureID[numTextures - 1],
                              xOffset, yOffset, textureWidth, textureHeight);
    
    // FIXME ceiling
                xOffset += (int)(tempGlyph->BBox().x2 - tempGlyph->BBox().x1 + padding);
    
    --remGlyphs;
    return tempGlyph;
  }
  
  err = face.Error();
  return NULL;

}
void
CanvasLayerD3D9::Initialize(const Data& aData)
{
  NS_ASSERTION(mSurface == nullptr, "BasicCanvasLayer::Initialize called twice!");

  if (aData.mDrawTarget) {
    mDrawTarget = aData.mDrawTarget;
    mSurface = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mDrawTarget);
    mNeedsYFlip = false;
    mDataIsPremultiplied = true;
  } else if (aData.mSurface) {
    mSurface = aData.mSurface;
    NS_ASSERTION(aData.mGLContext == nullptr,
                 "CanvasLayer can't have both surface and WebGLContext");
    mNeedsYFlip = false;
    mDataIsPremultiplied = true;
  } else if (aData.mGLContext) {
    mGLContext = aData.mGLContext;
    NS_ASSERTION(mGLContext->IsOffscreen(), "Canvas GLContext must be offscreen.");
    mDataIsPremultiplied = aData.mIsGLAlphaPremult;
    mNeedsYFlip = true;
  } else {
    NS_ERROR("CanvasLayer created without mSurface, mGLContext or mDrawTarget?");
  }

  mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);

  CreateTexture();
}
void DeviceVector2::Resize(unsigned int fSize)
{
	Destroy();
	height = fSize / width + 1;
	size = fSize;
	CreateTexture();
}
Exemple #13
0
void JRenderServer::RecreateDefaultRes()
{
    m_pDevice->ResourceManagerDiscardBytes( 0 );
    m_pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &m_pBackBuffer );
    m_pDevice->GetDepthStencilSurface( &m_pDepthStencil );

    for (int i = 0; i < m_VBuffers.size(); i++) 
    {
        VBInstance& vb = m_VBuffers[i];
        CreateVB( vb.m_Name.c_str(), vb.m_Size, !vb.m_bDynamic );
    }

    for (int i = 0; i < m_IBuffers.size(); i++) 
    {
        IBInstance& ib = m_IBuffers[i];
        CreateIB( ib.m_Name.c_str(), ib.m_Size, !ib.m_bDynamic );
    }

    for (int i = 0; i < m_Textures.size(); i++) 
    {
        TextureFile& tex = m_Textures[i];
        if (tex.m_Prop.m_PoolType == PoolType_Video)
        {
            CreateTexture( tex.m_Prop );
        }
    }

    CreateQuadIB();
} // JRenderServer::RecreateDefaultRes
bool CD3DTextTexture::Create(LOGFONT * pLogFont,int Width,int Height,int MipLevels,D3DCOLOR FontColor)
{
	//HRESULT hr;

	if(pLogFont)
	{	
		if(!SetFont(pLogFont))
			return false;		
	}

	SAFE_RELEASE(m_pTexture);
	
	if(!CreateTexture(Width,Height,D3DFMT_DXT5,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MipLevels))
		return false;	

	if(m_pFX==NULL)
		m_pFX=m_pManager->GetDevice()->GetFXManager()->LoadFXFromMemory(_T("TEXT_TEXTURE_FX_NT"),(VOID *)TEXT_TEXTURE_FX_NT,(int)strlen(TEXT_TEXTURE_FX_NT));

	m_Width=Width;
	m_Height=Height;
	m_Color=FontColor;
	m_MipLevels=MipLevels;
	m_WantUpdate=true;

	if(m_pManager)
	{
		m_pManager->AddAniTexture(this);
	}
	//UpdateTexture();
	return true;
}
Exemple #15
0
static void Init()
{
    GLenum result = glewInit();
    assert(result == GLEW_OK);

    auto version = ::glGetString(GL_VERSION);
    PRINTF("GL Version(%s)\n", version);

    CALL_GL_API(::glClipControl(
        GL_LOWER_LEFT,
        GL_ZERO_TO_ONE));

    CALL_GL_API(::glFrontFace(GL_CCW));

    CALL_GL_API(::glViewport(0, 0, WIDTH, HEIGHT));
    CALL_GL_API(::glDepthRangef(0.0f, 1.0f));


    g_vs = CreateShader("shader/vs.glsl", GL_VERTEX_SHADER);
    g_fs = CreateShader("shader/fs.glsl", GL_FRAGMENT_SHADER);

    g_program = CreateShaderProgram(g_vs, g_fs);

    g_tex = CreateTexture();
}
Exemple #16
0
void Item(int i, const char* model, const char* icon, bool equip, int delay, int ammo, int clip, int reloadrate, float damage, float range, int split, float inacc)
{
	g_lastItem = i;
	CItemType* t = &g_itemType[i];
    
	t->model = LoadModel(model, CVector3(1, 1, 1));
	if(equip)
	{
		if(ammo == PRIMARYAMMO)
			t->front = ModelFront(t->model, ANIM_SHOTSHOULDER_S, ANIM_SHOTSHOULDER_S+4);
		else if(ammo == SECONDARYAMMO)
			t->front = ModelFront(t->model, ANIM_SHOTGUNSHOT_S, ANIM_SHOTGUNSHOT_S+4);
		else if(ammo == TERTAMMO)
			t->front = ModelFront(t->model, ANIM_PISTOLSHOT_S, ANIM_PISTOLSHOT_S+4);
	}
	t->equip = equip;
	t->icon = CreateTexture(icon);
	t->delay = delay;
	t->ammo = ammo;
	t->clip = clip;
	t->reloadrate = reloadrate;
	t->damage = damage;
	t->range = range;
	t->split = split;
	t->inacc = inacc;
}
wiRenderer::TextureView wiTextureHelper::wiTextureHelperInstance::getRandom64x64()
{
	if (helperTextures[HELPERTEXTURE_RANDOM64X64] != nullptr)
	{
		return helperTextures[HELPERTEXTURE_RANDOM64X64];
	}

	static const int dataLength = 64 * 64 * 4;
	unsigned char* data = new unsigned char[dataLength];
	for (int i = 0; i < dataLength; i += 4)
	{
		data[i] = wiRandom::getRandom(0, 255);
		data[i + 1] = wiRandom::getRandom(0, 255);
		data[i + 2] = wiRandom::getRandom(0, 255);
		data[i + 3] = 255;
	}

	if (FAILED(CreateTexture(helperTextures[HELPERTEXTURE_RANDOM64X64], data, 64, 64, 4)))
	{
		delete[] data;
		return nullptr;
	}
	delete[] data;


	return helperTextures[HELPERTEXTURE_RANDOM64X64];
}
SharedSurface_Basic*
SharedSurface_Basic::Create(GLContext* gl,
                            const GLFormats& formats,
                            const IntSize& size,
                            bool hasAlpha)
{
    gl->MakeCurrent();
    GLuint tex = CreateTexture(gl, formats.color_texInternalFormat,
                               formats.color_texFormat,
                               formats.color_texType,
                               size);

    SurfaceFormat format = SurfaceFormat::B8G8R8X8;
    switch (formats.color_texInternalFormat) {
    case LOCAL_GL_RGB:
    case LOCAL_GL_RGB8:
        if (formats.color_texType == LOCAL_GL_UNSIGNED_SHORT_5_6_5)
            format = SurfaceFormat::R5G6B5;
        else
            format = SurfaceFormat::B8G8R8X8;
        break;
    case LOCAL_GL_RGBA:
    case LOCAL_GL_RGBA8:
        format = SurfaceFormat::B8G8R8A8;
        break;
    default:
        MOZ_CRASH("Unhandled Tex format.");
    }
    return new SharedSurface_Basic(gl, size, hasAlpha, format, tex);
}
Exemple #19
0
/**
 * Creates a wave mesh of the desired world size and number of vertices wide.
 */
void CreateWaveMesh(float scale, unsigned int vertexDim)
{
	DestroyWaveMesh();

	if (scale < 1)
	{
		scale = 1;
	}

	if (vertexDim < 2)
	{
		vertexDim = 2;
	}

	gWorldSize = scale;
	gVertexDim = vertexDim;
	gNumVertices = gVertexDim*gVertexDim;

	bool success;
	success = CreateVertexBuffer( scale, vertexDim );
	if ( success == false )
		return;

	success = CreateIndexBuffer( vertexDim );
	if ( success == false )
		return;

	success = CreateTexture();
	if ( success == false )
		return;

	gWaveStartTime = static_cast<float>(GetSystemTimeMs());
}
Exemple #20
0
static int 
SetupGraphics(void)
{
    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);

    CreateTexture(Width, Height);

    glDisable(GL_DEPTH_TEST);
    glActiveTexture(GL_TEXTURE0);
    
    glViewport(0, 0, Width, Height);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    TexCoords[3][0] = 0.0f;
    TexCoords[3][1] = 0.0f;
    TexCoords[2][0] = Width;
    TexCoords[2][1] = 0.0f;
    TexCoords[1][0] = Width;
    TexCoords[1][1] = Height;
    TexCoords[0][0] = 0.0f;
    TexCoords[0][1] = Height;

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, VertexPos);
    glClientActiveTexture(GL_TEXTURE0);
    glTexCoordPointer(2, GL_FLOAT, 0, TexCoords);
    return GL_NO_ERROR;
}
void
CanvasLayerD3D9::Initialize(const Data& aData)
{
  NS_ASSERTION(mSurface == nsnull, "BasicCanvasLayer::Initialize called twice!");

  if (aData.mDrawTarget) {
    mDrawTarget = aData.mDrawTarget;
    mNeedsYFlip = false;
    mDataIsPremultiplied = true;
  } else if (aData.mSurface) {
    mSurface = aData.mSurface;
    NS_ASSERTION(aData.mGLContext == nsnull,
                 "CanvasLayer can't have both surface and GLContext");
    mNeedsYFlip = false;
    mDataIsPremultiplied = true;
  } else if (aData.mGLContext) {
    NS_ASSERTION(aData.mGLContext->IsOffscreen(), "canvas gl context isn't offscreen");
    mGLContext = aData.mGLContext;
    mCanvasFramebuffer = mGLContext->GetOffscreenFBO();
    mDataIsPremultiplied = aData.mGLBufferIsPremultiplied;
    mNeedsYFlip = true;
  } else {
    NS_ERROR("CanvasLayer created without mSurface, mGLContext or mDrawTarget?");
  }

  mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);

  CreateTexture();
}
void Init(HWND hWnd)
{
	g_hWnd = hWnd;										// Assign the window handle to a global window handle
	GetClientRect(g_hWnd, &g_rRect);					// Assign the windows rectangle to a global RECT
	InitializeOpenGL(g_rRect.right, g_rRect.bottom);	// Init OpenGL with the global rect

	g_Load3ds.Import3DS(&g_3DModel, FILE_NAME);			// Load our .3DS file into our model structure

	// Go through all the materials
	for(int i = 0; i < g_3DModel.numOfMaterials; i++)
	{
		// Check to see if there is a file name to load in this material
		if(strlen(g_3DModel.pMaterials[i].strFile) > 0)
		{
			// Use the name of the texture file to load the bitmap, with a texture ID (i).
			// We pass in our global texture array, the name of the texture, and an ID to reference it.	
			CreateTexture(g_Texture, g_3DModel.pMaterials[i].strFile, i);			
		}

		// Set the texture ID for this material
		g_3DModel.pMaterials[i].texureId = i;
	}

	glEnable(GL_LIGHT0);								// Turn on a light with defaults set
	glEnable(GL_LIGHTING);								// Turn on lighting
	glEnable(GL_COLOR_MATERIAL);						// Allow color
}
int JResourceManager::CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height)
{
	map<string, int>::iterator itr = mQuadMap.find(quadName);

	if (itr == mQuadMap.end())
	{
		JTexture *tex = GetTexture(textureName);	
		if (tex == NULL)
		{
			int texId = CreateTexture(textureName);		// load texture if necessary
			tex = GetTexture(texId);
		}

		if (tex == NULL)								// no texture, no quad...
			return INVALID_ID;

		printf("creating quad:%s\n", quadName.c_str());

		int id = mQuadList.size();
		mQuadList.push_back(new JQuad(tex, x, y, width, height));

		mQuadMap[quadName] = id;
		
		return id;

	}
	else
		return itr->second;
}
void CDlgCreateSpecularTexture::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

  if( !pDX->m_bSaveAndValidate)
  {
    INDEX iExponent = DEFAULT_EXPONENT_POS;
    if( IsWindow( m_sliderSpecularExponent.m_hWnd))
    {
      iExponent = m_sliderSpecularExponent.GetPos();
    }
    CTString strNumericalExponent;
    strNumericalExponent.PrintF( "Value: %.1f", GetFactorForPercentage(iExponent));
    m_strNumericalExponent = strNumericalExponent;
  }
	
  //{{AFX_DATA_MAP(CDlgCreateSpecularTexture)
	DDX_Control(pDX, IDC_SPECULAR_EXPONENT, m_sliderSpecularExponent);
	DDX_Control(pDX, IDC_SPECULAR_COLOR, m_colorSpecular);
	DDX_Control(pDX, IDC_SIZE_IN_PIXELS, m_comboSizeInPixels);
	DDX_Control(pDX, IDC_LIGHT_COLOR, m_colorLight);
	DDX_Control(pDX, IDC_AMBIENT_COLOR, m_colorAmbient);
	DDX_Text(pDX, IDC_NUMERIC_EXPONENT_T, m_strNumericalExponent);
	DDX_Check(pDX, IDC_AUTO_ROTATE, m_bAutoRotate);
	//}}AFX_DATA_MAP
  
  if( (pDX->m_bSaveAndValidate) && IsWindow( m_sliderSpecularExponent.m_hWnd) )
  {                    
    INDEX iSlider = m_sliderSpecularExponent.GetPos();
    CreateTexture( CTString("temp\\SpecularTemp.tex"), GetFactorForPercentage( iSlider));
    CTextureData *pTD = (CTextureData *) m_moModel.mo_toSpecular.GetData();
    if( pTD != NULL) pTD->Reload();
    Invalidate( FALSE);
  }
}
wiRenderer::TextureView wiTextureHelper::wiTextureHelperInstance::getColor(const wiColor& color)
{
	if (colorTextures.find(color.rgba) != colorTextures.end())
	{
		return colorTextures[color.rgba];
	}

	static const int dataLength = 2 * 2 * 4;
	unsigned char* data = new unsigned char[dataLength];
	for (int i = 0; i < dataLength; i += 4)
	{
		data[i] = color.r;
		data[i + 1] = color.g;
		data[i + 2] = color.b;
		data[i + 3] = color.a;
	}

	wiRenderer::TextureView texture;
	if (FAILED(CreateTexture(texture, data, 2, 2, 4)))
	{
		delete[] data;
		return nullptr;
	}
	delete[] data;

	colorTextures[color.rgba] = texture;

	return texture;
}
Exemple #26
0
void Texture::SetTextureData2D(ImageData &ImgInfo, bool Reassign)
{
	if (Reassign) Destroy();

	CreateTexture(); // Make sure our texture exists.

	if (ImgInfo.Data.size() == 0 && !Reassign)
	{
		return;
	}

	auto img = ImgInfo.TempData ? ImgInfo.TempData : ImgInfo.Data.data();

	if (!TextureAssigned || Reassign) // We haven't set any data to this texture yet, or we want to regenerate storage
	{
		TextureAssigned = true;
		auto Dir = ImgInfo.Filename.filename().string();

		glPixelStorei(GL_UNPACK_ALIGNMENT, ImgInfo.Alignment);
		Renderer::SetTextureParameters(Dir);

		//glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, ImgInfo.Width, ImgInfo.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, ImgInfo.Data.data());
		glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, ImgInfo.Width, ImgInfo.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
	}
	else // We did, so let's update instead.
	{
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ImgInfo.Width, ImgInfo.Height, GL_RGBA, GL_UNSIGNED_BYTE, img);
	}

	w = ImgInfo.Width;
	h = ImgInfo.Height;
	fname = ImgInfo.Filename;
}
Exemple #27
0
void Test28()
{
	InitWindow();

	static Bitmap bm;
	bm.w = bm.h = 256; bm.form = BMFORMAT_B8G8R8A8; bm.pal = 0;
	bm.pix = (uchar*)malloc(bm.w * bm.h * 4);
	memset(bm.pix, 127, bm.w * bm.h * 4);

	static int px = 61, py = 89, vx = 2, vy = -3;
	*(uint*)(bm.pix + (py*bm.w + px) * 4) = -1;

	static texture t = CreateTexture(&bm, 1);
	while(!appexit)
	{
		px += vx; if(px < 0 || px >= 256) {px -= vx; vx = -vx;}
		py += vy; if(py < 0 || py >= 256) {py -= vy; vy = -vy;}
		*(uint*)(bm.pix + (py*bm.w + px) * 4) = -1;
		renderer->UpdateTexture(t, &bm);
		BeginDrawing();
		InitRectDrawing();
		SetTexture(0, t);
		DrawRect(0, 0, 256, 256, -1);
		EndDrawing();
		HandleWindow();
	}
}
HRESULT
D3DResourceManager::GetCachedDestTexture(D3DFORMAT format,
                                         D3DResource **ppTextureResource)
{
    J2dTraceLn(J2D_TRACE_INFO, "D3DRM::GetCachedDestTexture");

    RETURN_STATUS_IF_NULL(pCtx, E_FAIL);
    RETURN_STATUS_IF_NULL(ppTextureResource, E_FAIL);

    HRESULT res =
        GetStockTextureResource(D3DTR_CACHED_DEST_WIDTH,
                                D3DTR_CACHED_DEST_HEIGHT,
                                TRUE/*isRTT*/, FALSE/*isOpaque*/,
                                &format, 0, &pCachedDestTexture);
    if (SUCCEEDED(res)) {
        D3DSURFACE_DESC *pDesc = pCachedDestTexture->GetDesc();
        D3DCAPS9 *pDevCaps = pCtx->GetDeviceCaps();
        if ((format == pDesc->Format ||
             SUCCEEDED(pCtx->Get3DObject()->CheckDeviceFormatConversion(
                           pDevCaps->AdapterOrdinal,
                           pDevCaps->DeviceType, format, pDesc->Format))))
        {
            *ppTextureResource = pCachedDestTexture;
            return res;
        }
        // current texture doesn't fit, release and allocate a new one
        ReleaseResource(pCachedDestTexture);
        pCachedDestTexture = NULL;
    }
    res = CreateTexture(D3DTR_CACHED_DEST_WIDTH, D3DTR_CACHED_DEST_HEIGHT,
                        TRUE, FALSE, &format, 0,
                        &pCachedDestTexture);
    *ppTextureResource = pCachedDestTexture;
    return res;
}
void DeviceVector::Resize(unsigned int fSize)
{
	Destroy();
	height = (fSize + (width - 1)) / width;
	size = fSize;
	CreateTexture();
}
Exemple #30
0
    CTexture* CGraphicsDeviceGLES2::CreateTexture(
        IZ_UINT width,
        IZ_UINT height,
        E_GRAPH_PIXEL_FMT fmt,
        void* data)
    {
        CTexture* texture = CreateTexture(
            width, height, 1,
            fmt,
            E_GRAPH_RSC_USAGE_STATIC);
        VRETURN_NULL(texture != IZ_NULL);

        void* dst = IZ_NULL;
        VRETURN_NULL(
            texture->Lock(0, (void**)&dst, IZ_FALSE));

        IZ_UINT bpp = CGraphUtil::GetBPP(fmt);
        IZ_UINT size = width * height * bpp;

        memcpy(dst, data, size);

        texture->Unlock(0);

        return texture;
    }