Beispiel #1
0
TGrass *GrassCreate(const float pX,
                    const float pY,
                    const float pZ,
                    const uint32 pNumSegments,
                    const TGrassType pType)
{
    TRenderEntity *lSegment = RenderEntityCreateQuadTextured(1.0f, 1.0f, FLARE_TEXTURE);
    if(lSegment == NULL)
        return NULL;
        
    TShader *lShader = ShaderCreate(BILLBOARDING_SHADER_VS, NULL);

    if(lShader!=NULL)
    {
        MaterialAddShader(lSegment->mMaterial, lShader);
        ShaderDestroy(lShader);
        lShader = 0;
    }

    CLASS_CREATE(TGrass);
    
    Matrix4GetIdentity(&this->mModelView);
    this->mSegment = lSegment;
    this->mTTT = RANDOM(512)+10.0f;

    GrassSetColor(this, 1.0f, 1.0f, 1.0f, 1.0f);
    GrassSetPosition(this, pX, pY, pZ);
    GrassSetNumSegments(this, pNumSegments);
    GrassSetType(this, pType);
    
    CLASS_INSTANCE();
}
Beispiel #2
0
TRenderEntity *RenderEntityCreate(void)
{
    CLASS_CREATE(TRenderEntity);
    
    this->mMaterial = NULL;
    this->mGeom = NULL;
    
    RenderEntityReset(this);
    
    CLASS_INSTANCE();
}
Beispiel #3
0
TMaterial *MaterialCreate(void)
{
    CLASS_CREATE(TMaterial);

    int i;
    for(i=0;i<MATERIAL_MAX_TEXTURES;i++)
        this->mTextures[i] = NULL;

    this->mShader = NULL;
    
    MaterialSetColor(this,gColor[0],gColor[1],gColor[2],gColor[3]);

    CLASS_INSTANCE();
}
Beispiel #4
0
static inline int usbhost_classbind(FAR struct usbhost_hubport_s *hport,
                                    const uint8_t *configdesc, int desclen,
                                    struct usbhost_id_s *id,
                                    FAR struct usbhost_class_s **usbclass)
{
  FAR struct usbhost_class_s *devclass;
  FAR const struct usbhost_registry_s *reg;
  int ret = -EINVAL;

  /* Is there is a class implementation registered to support this device. */

  reg = usbhost_findclass(id);
  uvdbg("usbhost_findclass: %p\n", reg);
  if (reg != NULL)
    {
      /* Yes.. there is a class for this device.  Get an instance of
       * its interface.
       */

      ret = -ENOMEM;
      devclass = CLASS_CREATE(reg, hport, id);
      uvdbg("CLASS_CREATE: %p\n", devclass);
      if (devclass != NULL)
        {
          /* Then bind the newly instantiated class instance */

          ret = CLASS_CONNECT(devclass, configdesc, desclen);
          if (ret < 0)
            {
              /* On failures, call the class disconnect method which
               * should then free the allocated devclass instance.
               */

              udbg("CLASS_CONNECT failed: %d\n", ret);
              CLASS_DISCONNECTED(devclass);
            }
          else
            {
              *usbclass = devclass;
            }
        }
    }

  uvdbg("Returning: %d\n", ret);
  return ret;
}
Beispiel #5
0
TGrass *GrassClone(const TGrass *pGrass)
{
    CLASS_CREATE(TGrass);
    
    Matrix4Copy(&this->mModelView, &pGrass->mModelView);
    this->mSegment = pGrass->mSegment;
    this->mTTT = RANDOM(512)+10.0f;
    this->mSegment->mRefCount++;
    
    int i;
    for(i=0;i<4;i++)
        this->mColor[i] = pGrass->mColor[i];
    
    GrassSetNumSegments(this, pGrass->mNumSegments);
    GrassSetType(this, pGrass->mType);
    
    CLASS_INSTANCE();
}
Beispiel #6
0
TMusic *MusicCreate(const char *pFileName)
{
    Mix_Music *lMusic = Mix_LoadMUS(pFileName);
 	if(lMusic==NULL)
	{
		printf("MusicCreate: %s ...\n", Mix_GetError());
		return NULL;
	}
	else
	{
		printf("MusicCreate: %s ...\n", pFileName);
	}

    CLASS_CREATE(TMusic);
    
    this->mTicks = 0;
    this->mMusicId = lMusic;
    Mix_SetPostMix(MusicCallback, (void *)this);
    
    CLASS_INSTANCE();
}
Beispiel #7
0
TTexture *TextureCreateEmpty(const uint32 pWidth, const uint32 pHeight)
{
    CLASS_CREATE(TTexture);

    glGenTextures(1, &this->mTextureId);
    
    TextureBegin(this);
    /*glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );*/
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
#ifdef GL_CLAMP_TO_EDGE
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#else
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#endif
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, pWidth, pHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    TextureEnd();
    
    CLASS_INSTANCE();
}
/**
 * Create initial class object at bootstrap time.
 */
void DirectoryClass::createInstance()
{
    CLASS_CREATE(Directory);
}
Beispiel #9
0
TGarden *GardenCreate(const float pWidth, const float pHeight, const float pX, const float pY, const float pZ)
{
    /*! Create Ground Plane */
    TRenderEntity *lPlane = RenderEntityCreateQuadTextured(pWidth, pHeight, GARDEN_GROUND_TEXTURE);
    if(lPlane == NULL)
        return NULL;
        
    CLASS_CREATE(TGarden);

    Matrix4GetIdentity(&this->mModelView);
    Matrix4SetTranslate(&this->mModelView, pX, pY, pZ);

    this->mGround[0] = RenderEntityClone(lPlane);
    RenderEntityRotate(this->mGround[0], 90.0f, 1.0f, 0.0f, 0.0f);
    
    this->mGround[1] = RenderEntityClone(lPlane);
    RenderEntityRotate(this->mGround[1],-90.0f, 1.0f, 0.0f, 0.0f);
    
    RenderEntityDestroy(lPlane);
        
    /*! Dummy Grass which will be cloned as necessary */
    TGrass *lGrass = GrassCreate(0.0f, 0.0f, 0.0f, 0, GRASS_SIN_WAVE);
    if(lGrass!=NULL)
    {    
        int i,j;
        
        vec2 lOffsets[GARDEN_MAX_GRASS_RINGS] = 
        {
            {0.0f, 0.0f},
            {0.0f, 0.0f},
            {0.0f, 0.0f}
        };
        
        for(j=0;j<GARDEN_MAX_GRASS_RINGS;j++)
        for(i=0;i<GARDEN_MAX_GRASS_LINES;i++)
        {
            TGrass *lClone = GrassClone(lGrass);
            
            float lAngle = i * (2.0*M_PI/GARDEN_MAX_GRASS_LINES);
            float lX = cos(lAngle)*(15.0f - (j*5));
            float lZ = sin(lAngle)*(15.0f - (j*5));
                        
            GrassSetPosition(lClone, lX + lOffsets[j][0], 0.0f, lZ + lOffsets[j][1]);
            
            //! Random Type
            GrassSetType(lClone, RANDOM(GRASS_MAX_TYPES));
            
            //! Random Number of Segments
            GrassSetNumSegments(lClone, RANDOM(GRASS_MAX_SEGMENTS)+16);
            
            //! Inner Ring is Red
            if(j == GARDEN_MAX_GRASS_RINGS-1)
            {
                GrassSetColor(lClone, 0.8f, 0.0f, 0.0f, 1.0f);
            }
            
            this->mGrass[j][i] = lClone;
        }
        
        GrassDestroy(lGrass);
    }
    else
    {
        printf("Garden: grass couldn't be created for some reason. Crash is ahead!\n");
    }

    CLASS_INSTANCE();
}
Beispiel #10
0
/**
 * Create initial class object at bootstrap time.
 */
void MethodClass::createInstance()
{
    CLASS_CREATE(Method);
}
/**
 * Create initial class object at bootstrap time.
 */
void QueueClass::createInstance()
{
    CLASS_CREATE(Queue);
}
/**
 * Create initial class object at bootstrap time.
 */
void SupplierClass::createInstance()
{
    CLASS_CREATE(Supplier);
}
Beispiel #13
0
/**
 * Create initial class object at bootstrap time.
 */
void RexxSupplier::createInstance()
{
    CLASS_CREATE(Supplier, "Supplier", RexxClass);
}
Beispiel #14
0
TTexture *TextureCreate(const char *pFileName, bool pMipMaps)
{
	SDL_Surface *lImage = IMG_Load(pFileName);
	if(lImage==NULL)
	{
		printf("TextureCreate: %s ...\n", IMG_GetError());
		return NULL;
	}
	else
	{
		printf("TextureCreate: %s ...\n", pFileName);
	}

	/* Flip Image */
	{
		uint8 *lTmpBuf = (uint8 *) malloc(lImage->pitch * sizeof(uint8));
		uint8 *lRowHi = (uint8 *) lImage->pixels;
		uint8 *lRowLo = lRowHi + ((lImage->h - 1) * lImage->pitch);

		int lMiddle = (int) lImage->h/2; int i;
		for(i=0;i<lMiddle;i++)
		{
			memcpy(lTmpBuf, lRowHi, lImage->pitch);
			memcpy(lRowHi, 	lRowLo, lImage->pitch);
			memcpy(lRowLo, 	lTmpBuf,lImage->pitch);

			lRowHi += lImage->pitch;
			lRowLo -= lImage->pitch;
		}

		free(lTmpBuf);
	}

	CLASS_CREATE(TTexture);
	
    this->mHash = hash(pFileName);
    this->mWidth = lImage->w;
    this->mHeight= lImage->h;

	glGenTextures(1, &this->mTextureId);
	
	TextureBegin(this);

    if(pMipMaps)
    {
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    }
    else
    {
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    }
    /*glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );*/

#ifdef GL_CLAMP_TO_EDGE
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#else
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#endif

	/* Determine Image Properties and Upload the Texture Data */
	{
		uint32 lFormat = GL_RGBA;
	
		#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		uint32 lRmask = 0xff000000;
		#else
		uint32 lRmask = 0x000000ff;
		#endif

		switch(lImage->format->BytesPerPixel)
		{
			case 4: 
				lFormat = (lImage->format->Rmask == lRmask) ? GL_RGBA : GL_BGRA;
				break;

			case 3:
			default:
				lFormat = (lImage->format->Rmask == lRmask) ? GL_RGB : GL_BGR;
				break;
		}

		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, lImage->w, lImage->h, 0,
					  lFormat, GL_UNSIGNED_BYTE, lImage->pixels );
		
		if(pMipMaps)
		{			
	        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, lImage->w, lImage->h, lFormat, GL_UNSIGNED_BYTE, lImage->pixels);
	    }
	}
	
	TextureEnd();

	SDL_FreeSurface(lImage);
	CLASS_INSTANCE();
}
/**
 * Create initial class object at bootstrap time.
 */
void StemClass::createInstance()
{
    CLASS_CREATE(Stem);
}