コード例 #1
0
//! \brief bind render target as texture to opengl
DRReturn RenderToTexture::bindTexture()
{
    glEnable(GL_TEXTURE_2D);
    //bind to the new texture ID
	glBindTexture(GL_TEXTURE_2D, mTextureID);

	if(DRGrafikError("RenderToTexture::bindTexture")) return DR_ERROR;
    
    return DR_OK;
}
コード例 #2
0
DRReturn RenderToTexture::saveToImage(const char* path)
{
    DRIImage* image = DRIImage::newImage();
    u8* buffer = (u8*)malloc(mSize.x*mSize.y*4*sizeof(u8));
    glBindTexture(GL_TEXTURE_2D, mTextureID);
    glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
    if(DRGrafikError("RenderToTexture::saveToImage")) LOG_ERROR("Fehler bei getting texture Data!", DR_ERROR);
    image->setSize(mSize);
    image->setImageFormat(-1);
    image->setPixel(buffer);
    if(image->saveIntoFile(path))
        LOG_ERROR("fehler bei save", DR_ERROR);
    
    free(buffer);
    delete image;
    
    return DR_OK;
}
コード例 #3
0
DRReturn PlanetSektor::render(float fTime, Camera* cam)
{
#if SDL_VERSION_ATLEAST(1,3,0)
	Uint8 *keystate = SDL_GetKeyboardState(NULL);
#else
	Uint8 *keystate = SDL_GetKeyState(NULL);
#endif
    
    //if(isObjectInSektor(cam->getSektorPosition())) return DR_OK;
	//Unit distance1 = Vector3Unit(mSektorPosition - cam->getSektorPosition()).length();
    //Unit distance1 = Vector3Unit(mSektorPosition - mLastRelativeCameraPosition).length();    
    Unit distance1 = (-mLastRelativeCameraPosition).length();    
	//DRVector3 diff = Vector3Unit(mSektorPosition - cam->getSektorPosition()).convertTo(KM).getVector3();

    distance1 = distance1.convertTo(mRadius.getType());
    double distance2 = 200.0f;
    Unit radius1 = mRadius;
    double radius2 = ((radius1 * distance2) / distance1);

    
	//DRVector3 pos = (mSektorPosition - cam->getSektorPosition()).getVector3().normalize();
    //DRVector3 pos = (mSektorPosition - mLastRelativeCameraPosition).getVector3().normalize();
    DRVector3 pos = (-mLastRelativeCameraPosition).getVector3().normalize();
//    DRVector3 relCameraPos = -pos*distance1/mRadius;
     pos *= static_cast<DRReal>(distance2);
/*   printf("\r %f %f %f, %.8f, %s  x:%s y:%s z:%s (%f %f %f)", pos.x, pos.y, pos.z, radius2, distance1.print().data(),
									   absCameraPosition.x.print().data(), absCameraPosition.y.print().data(),
									   absCameraPosition.z.print().data(), diff.x, diff.y, diff.z);
										   //*/
    //glTranslatef(pos.x, pos.y, pos.z);
    //glScaled(radius2, radius2, radius2);
	
    mMatrix = DRMatrix::scaling(DRVector3(static_cast<DRReal>(radius2))) * DRMatrix::translation(pos) * cam->getKameraMatrixRotation();
	
	//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	//if(mRenderer && !isObjectInSektor(cam->getSektorPosition()))
    //DRReturn ret = mRenderer->render(fTime, cam);
    if(!isObjectInSektor(mLastRelativeCameraPosition))
    {
        mNotRenderSeconds = 0.0f;
        if(!mRenderer)
            mRenderer = new RenderPlanet(mID, getSektorPathName(), &mPlanetNoiseParameters);
        if(!mRenderer) LOG_ERROR("no renderer", DR_ERROR);
        
        if(radius2 > 160.0f) mRenderer->setCurrentDetail(10);
        else if(radius2 > 140.0f) mRenderer->setCurrentDetail(9);
        else if(radius2 > 120.0f) mRenderer->setCurrentDetail(8);
        else if(radius2 > 90.0f) mRenderer->setCurrentDetail(7);
        else if(radius2 > 70.0f) mRenderer->setCurrentDetail(6);
        else if(radius2 > 30.0f) mRenderer->setCurrentDetail(5);
        else if(radius2 > 25.0f) mRenderer->setCurrentDetail(4);
        else if(radius2 > 15.0f) mRenderer->setCurrentDetail(3);
        else if(radius2 > 5.0f) mRenderer->setCurrentDetail(2);
        else if(radius2 > 1.0f) mRenderer->setCurrentDetail(1);
        else mRenderer->setCurrentDetail(0);
    
      //GlobalRenderer::getSingleton().getPlanetShaderPtr()->bind();
        ShaderProgram* shader = mRenderer->getShaderProgram();
        if(!shader) LOG_ERROR("RenderPlanet hasn't valid shader", DR_ERROR);
        shader->bind();

        shader->setUniformMatrix("modelview", mMatrix);
        shader->setUniformMatrix("projection", GlobalRenderer::Instance().getProjectionMatrix().transpose());
        DRGrafikError("PlanetSektor::render");
        
        DRReturn ret = mRenderer->render(fTime, cam);
        shader->unbind();
//		GlobalRenderer::getSingleton().getPlanetShaderPtr()->unbind();
        if(ret) LOG_ERROR("Fehler bei call planet renderer", DR_ERROR);
        //child didn't need to render
        return DR_NOT_ERROR;
        //return DR_OK;
    } 
    else
    {
        mNotRenderSeconds += fTime;
    }
    
    return DR_OK;
}