Ejemplo n.º 1
0
void ofxFBOTexture::allocate(int w, int h, bool autoClear, int numSamples) {
        _isActive = false;

        texData.width = w;
        texData.height = h;

	if( numSamples == 0 ){
		bUseMultiSample = false;
	}else{
		bUseMultiSample = true;
	}

    if (GLEE_ARB_texture_rectangle){
        texData.tex_w = w;
        texData.tex_h = h;
        texData.textureTarget = GL_TEXTURE_RECTANGLE_ARB;
    } else {
        texData.tex_w = ofNextPow2(w);
        texData.tex_h = ofNextPow2(h);
    }

        if (GLEE_ARB_texture_rectangle){
                texData.tex_t = w;
                texData.tex_u = h;
        } else {
                texData.tex_t = 1.0f;
                texData.tex_u = 1.0f;
        }

        // attempt to free the previous bound texture, if we can:
        clean();

        texData.width = w;
        texData.height = h;
        texData.bFlipTexture = true;
        texData.glType = GL_RGBA;

        this->autoClear = autoClear;
		

		if( bUseMultiSample ){

			// MULTISAMPLE //
			
			//THEO Create the render buffer for depth
			glGenRenderbuffersEXT(1, &depthBuffer);
			glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
			glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, numSamples, GL_DEPTH_COMPONENT, texData.tex_w, texData.tex_h);

			//THEO multi sampled color buffer
			glGenRenderbuffersEXT(1, &colorBuffer);
			glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorBuffer);
			glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, numSamples, GL_RGBA8, texData.tex_w, texData.tex_h);
			
			
			//THEO create fbo for multi sampled content and attach depth and color buffers to it
			glGenFramebuffersEXT(1, &mfbo);
			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mfbo);
			glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorBuffer);
			glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);
		}else{
			
			//THEO Create the render buffer for depth
			glGenRenderbuffersEXT(1, &depthBuffer);
			glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
			glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texData.tex_w, texData.tex_h);
		}
		
		// NORMAL // 
		
        // create & setup texture
        glGenTextures(1, (GLuint *)(&texData.textureID));   // could be more then one, but for now, just one
        glBindTexture(texData.textureTarget, (GLuint)(texData.textureID));
        glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameterf(texData.textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameterf(texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(texData.textureTarget, 0, texData.glType, texData.tex_w, texData.tex_h, 0, texData.glType, GL_UNSIGNED_BYTE, 0);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

		// create & setup FBO
        glGenFramebuffersEXT(1, &fbo);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
		
        // attach it to the FBO so we can render to it
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texData.textureTarget, (GLuint)texData.textureID, 0);

		
		if( !bUseMultiSample ){
			// Attach the depth render buffer to the FBO as it's depth attachment
			glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);
		}

        GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
        if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
                cout<<"glBufferTexture failed to initialize. Perhaps your graphics card doesnt support the framebuffer extension? If you are running osx prior to system 10.5, that could be the cause"<<endl;
                std::exit(1);
        }
        clear(0, 0, 0, 0);

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

        texData.bAllocated = true;

}
Ejemplo n.º 2
0
/* initialise textures */
static void inittextures(ModeInfo * mi)
{
    firestruct *fs = &fire[MI_SCREEN(mi)];

#if defined( I_HAVE_XPM )
    if (do_texture) {

	glGenTextures(1, &fs->groundid);
#ifdef HAVE_GLBINDTEXTURE
	glBindTexture(GL_TEXTURE_2D, fs->groundid);
#endif /* HAVE_GLBINDTEXTURE */

        if ((fs->gtexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi),
			 MI_COLORMAP(mi), ground)) == None) {
	    (void) fprintf(stderr, "Error reading the ground texture.\n");
	    glDeleteTextures(1, &fs->groundid);
            do_texture = False;
	    fs->groundid = 0;
	    fs->treeid   = 0;
	    return;
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    clear_gl_error();
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                 fs->gtexture->width, fs->gtexture->height, 0,
                 GL_RGBA,
                 /* GL_UNSIGNED_BYTE, */
                 GL_UNSIGNED_INT_8_8_8_8_REV,
                 fs->gtexture->data);
    check_gl_error("texture");

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

        if (fs->num_trees)
	{
	    glGenTextures(1, &fs->treeid);
#ifdef HAVE_GLBINDTEXTURE
	    glBindTexture(GL_TEXTURE_2D,fs->treeid);
#endif /* HAVE_GLBINDTEXTURE */
            if ((fs->ttexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi),
			 MI_COLORMAP(mi), tree)) == None) {
	      (void)fprintf(stderr,"Error reading tree texture.\n");
	      glDeleteTextures(1, &fs->treeid);
	      fs->treeid    = 0;
              fs->num_trees = 0; 
	      return;
	    }

        clear_gl_error();
	    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                     fs->ttexture->width, fs->ttexture->height, 0,
                     GL_RGBA,
                     /* GL_UNSIGNED_BYTE, */
                     GL_UNSIGNED_INT_8_8_8_8_REV,
                     fs->ttexture->data);
        check_gl_error("texture");

	    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

	    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

	    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
	}
    }
    else
    {
	fs->groundid = 0;	/* default textures */
	fs->treeid   = 0;
    }
#else /* !I_HAVE_XPM */
  do_texture = False;
  fs->groundid = 0;       /* default textures */
  fs->treeid = 0;
#endif /* !I_HAVE_XPM */
}
Ejemplo n.º 3
0
/*
 * r_init
 * Perform any one-time GL state changes.
 */
static void r_init()
{
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	//NEW TEXTURE STUFF
	glEnable(GL_TEXTURE_2D);
	//You might want to play with changing the modes
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	//These functions load my custom textures.
	//r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/uparrow.tga",
	//		&myGLTexture, &myTexWidth, &myTexHeight, &myTexBPP);

	//Testing
	//"C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face1.tga"
	face1data = r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face1.tga",
			&face1, &face1Width, &face1Height, &face1BPP, &face1Type);
	face2data = r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face2.tga",
			&face2, &face2Width, &face2Height, &face2BPP, &face2Type);
	face3data = r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face3.tga",
			&face3, &face3Width, &face3Height, &face3BPP, &face3Type);
	face4data = r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face4.tga",
			&face4, &face4Width, &face4Height, &face4BPP, &face4Type);
	face5data = r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face5.tga",
			&face5, &face5Width, &face5Height, &face5BPP, &face5Type);
	face6data = r_image_loadTGA("C:/Users/Cory/workspace/FunWithSDL/Debug/textures/face6.tga",
			&face6, &face6Width, &face6Height, &face6BPP, &face6Type);


	//*****************************************************************************
		glGenTextures(1, &face1);
		glBindTexture(GL_TEXTURE_2D, face1);

		//Default OpenGL settings have GL_TEXTURE_MAG/MIN_FILTER set to use
		//mipmaps... without these calls texturing will not work properly.
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

		//Upload image data to OpenGL
		glTexImage2D(GL_TEXTURE_2D, 0, face1Type, face1Width, face1Height,
				0, face1Type, GL_UNSIGNED_BYTE, face1data);


	//*****************************************************************************
	glGenTextures(1, &face2);
	glBindTexture(GL_TEXTURE_2D, face2);

	//Default OpenGL settings have GL_TEXTURE_MAG/MIN_FILTER set to use
	//mipmaps... without these calls texturing will not work properly.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	//Upload image data to OpenGL
	glTexImage2D(GL_TEXTURE_2D, 0, face2Type, face2Width, face2Height,
			0, face2Type, GL_UNSIGNED_BYTE, face2data);

	//*************************************************************************
	glGenTextures(1, &face3);
	glBindTexture(GL_TEXTURE_2D, face3);

	//Default OpenGL settings have GL_TEXTURE_MAG/MIN_FILTER set to use
	//mipmaps... without these calls texturing will not work properly.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	//Upload image data to OpenGL
	glTexImage2D(GL_TEXTURE_2D, 0, face3Type, face3Width, face3Height,
		0, face3Type, GL_UNSIGNED_BYTE, face3data);

	//*************************************************************************
	glGenTextures(1, &face4);
	glBindTexture(GL_TEXTURE_2D, face4);

	//Default OpenGL settings have GL_TEXTURE_MAG/MIN_FILTER set to use
	//mipmaps... without these calls texturing will not work properly.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	//Upload image data to OpenGL
	glTexImage2D(GL_TEXTURE_2D, 0, face4Type, face4Width, face4Height,
		0, face4Type, GL_UNSIGNED_BYTE, face4data);

	//*************************************************************************
	glGenTextures(1, &face5);
	glBindTexture(GL_TEXTURE_2D, face5);

	//Default OpenGL settings have GL_TEXTURE_MAG/MIN_FILTER set to use
	//mipmaps... without these calls texturing will not work properly.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	//Upload image data to OpenGL
	glTexImage2D(GL_TEXTURE_2D, 0, face5Type, face5Width, face5Height,
		0, face5Type, GL_UNSIGNED_BYTE, face5data);
	//*************************************************************************
	glGenTextures(1, &face6);
	glBindTexture(GL_TEXTURE_2D, face6);

	//Default OpenGL settings have GL_TEXTURE_MAG/MIN_FILTER set to use
	//mipmaps... without these calls texturing will not work properly.
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	//Upload image data to OpenGL
	glTexImage2D(GL_TEXTURE_2D, 0, face6Type, face6Width, face6Height,
		0, face6Type, GL_UNSIGNED_BYTE, face6data);

	camera_init();

	r_setupProjection();
	r_loadGameMeshes();
}
Ejemplo n.º 4
0
bool TeaPot::Initialize(double x, double y, double z)
{
    ubyte   *image_data;
    int	    image_height, image_width;
    
    // Load the image for the texture. The texture file has to be in
    // a place where it will be found.
    if ( ! ( image_data = (ubyte*)tga_load("Teapot.tga", &image_width,
                                           &image_height, TGA_TRUECOLOR_24) ) )
    {
        fprintf(stderr, "Ground::Initialize: Couldn't load grass.tga\n");
        return false;
    }
    
    // This creates a texture object and binds it, so the next few operations
    // apply to this texture.
    glGenTextures(1, &texture_obj);
    glBindTexture(GL_TEXTURE_2D, texture_obj);
    
    // This sets a parameter for how the texture is loaded and interpreted.
    // basically, it says that the data is packed tightly in the image array.
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
    // This sets up the texture with high quality filtering. First it builds
    // mipmaps from the image data, then it sets the filtering parameters
    // and the wrapping parameters. We want the grass to be repeated over the
    // ground.
    gluBuild2DMipmaps(GL_TEXTURE_2D,3, image_width, image_height, GL_RGB, GL_UNSIGNED_BYTE, image_data);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
    
    float maximumAnistropy;
    //get the value
    glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maximumAnistropy);
    
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
    
    // This says what to do with the texture. Modulate will multiply the
    // texture by the underlying color.
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    
    // Now do the geometry. Create the display list.
    display_list = glGenLists(1);
    glNewList(display_list, GL_COMPILE);
    
    //glColor3f(119/255.0f,11/255.0f,0);
    
    glDisable(GL_CULL_FACE);
    
    // The surface normal is up for the ground.
	glNormal3f(0.0, 0.0, 1.0);
    
    glRotated(90, 1, 0, 0);
    
    glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture_obj);
    glutSolidTeapot(3);
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_CULL_FACE);
    
    glEndList();
    
    // We only do all this stuff once, when the GL context is first set up.
    initialized = true;
    
    return true;
}
Ejemplo n.º 5
0
void MeshRenderer :: setMesh(const Mesh& mesh)
{
    m_pbuffer->makeCurrent();

    clearVertexBufferObject();
    m_mesh = &mesh;

    GLuint vbo_id = -1, vbo_faces_id = -1;
    glGenBuffersARB(1, &vbo_id);
    if (mesh.hasFaces())
        glGenBuffersARB(1, &vbo_faces_id);

    VertexBufferObject& vbo = m_vertex_buffer_object;
    vbo.nb_faces = 0;
    vbo.vertex_id = vbo_id;
    vbo.faces_id = vbo_faces_id;
    vbo.has_faces = mesh.hasFaces();
    vbo.has_color = mesh.hasColors();
    vbo.has_texcoords = mesh.hasTexcoords();
    vbo.color_offset = mesh.vertices.size()*sizeof(Vec3f);
    vbo.texture_offset = mesh.vertices.size()*sizeof(Vec3f) + mesh.colors.size() * sizeof(Vec3b);
    vbo.nb_vertices = mesh.vertices.size();

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo.vertex_id);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB,
                    mesh.colors.size()*sizeof(Vec3b)
                    + mesh.vertices.size()*sizeof(Vec3f)
                    + mesh.texcoords.size()*sizeof(Point2f), // size
                    0, // null pointer: just allocate memory
                    GL_STATIC_DRAW_ARB);
    glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, mesh.vertices.size()*sizeof(Vec3f), &mesh.vertices[0]);

    if (vbo.has_texcoords)
        glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, vbo.texture_offset, mesh.texcoords.size()*sizeof(Point2f), &mesh.texcoords[0]);
    else if (vbo.has_color)
        glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, vbo.color_offset, mesh.colors.size()*sizeof(Vec3b), &mesh.colors[0]);

    if (vbo.has_faces)
    {
        vbo.nb_faces = mesh.faces.size();
        glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, vbo.faces_id);
        glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
                        mesh.faces.size() * 3 * sizeof(GLuint), // size
                        (GLuint*)&mesh.faces[0],
                        GL_STATIC_DRAW_ARB);
    }

    if (mesh.texture.data)
    {
        glGenTextures( 1, &vbo.texture_id );
        glBindTexture( GL_TEXTURE_2D, vbo.texture_id );
        glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
        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_BASE_LEVEL,0);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0,
                     GL_RGB8, mesh.texture.cols, mesh.texture.rows,
                     0, GL_BGR, GL_UNSIGNED_BYTE,mesh.texture.data);
    }   

    vbo.initialized = true;
}
static void
drawParticles (CompScreen * s, ParticleSystem * ps)
{
    glPushMatrix ();

    glEnable (GL_BLEND);
    if (ps->tex)
    {
	glBindTexture (GL_TEXTURE_2D, ps->tex);
	glEnable (GL_TEXTURE_2D);
    }
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    /* Check that the cache is big enough */
    if (ps->hardLimit > ps->vertex_cache_count)
    {
	ps->vertices_cache =
	    realloc (ps->vertices_cache,
		    ps->hardLimit * 4 * 3 * sizeof (GLfloat));
	ps->vertex_cache_count = ps->hardLimit;
    }

    if (ps->hardLimit > ps->coords_cache_count)
    {
	ps->coords_cache =
	    realloc (ps->coords_cache,
		    ps->hardLimit * 4 * 2 * sizeof (GLfloat));
	ps->coords_cache_count = ps->hardLimit;
    }

    if (ps->hardLimit > ps->color_cache_count)
    {
	ps->colors_cache =
	    realloc (ps->colors_cache,
		    ps->hardLimit * 4 * 4 * sizeof (GLfloat));
	ps->color_cache_count = ps->hardLimit;
    }

    if (ps->darken > 0)
    {
	if (ps->dcolors_cache_count < ps->hardLimit)
	{
	    ps->dcolors_cache =
		realloc (ps->dcolors_cache,
			ps->hardLimit * 4 * 4 * sizeof (GLfloat));
	    ps->dcolors_cache_count = ps->hardLimit;
	}
    }

    GLfloat *dcolors  = ps->dcolors_cache;
    GLfloat *vertices = ps->vertices_cache;
    GLfloat *coords   = ps->coords_cache;
    GLfloat *colors   = ps->colors_cache;

    int cornersSize = sizeof (GLfloat) * 8;
    int colorSize   = sizeof (GLfloat) * 4;

    GLfloat cornerCoords[8] = {0.0, 0.0,
			       0.0, 1.0,
			       1.0, 1.0,
			       1.0, 0.0};

    int numActive = 0;

    Particle *part = ps->particles;
    int i;
    for (i = 0; i < ps->hardLimit; i++, part++)
    {
	if (part->t > 0.0f)
	{
	    numActive += 4;

	    float cOff = part->s / 2.;		//Corner offset from center

	    if (part->t > ps->tnew)		//New particles start larger
		cOff += (part->snew - part->s) * (part->t - ps->tnew)
			/ (1. - ps->tnew) / 2.;
	    else if (part->t < ps->told)	//Old particles shrink
		cOff -= part->s * (ps->told - part->t) / ps->told / 2.;

	    //Offsets after rotation of Texture
	    float offA = cOff * (cos (part->phi) - sin (part->phi));
	    float offB = cOff * (cos (part->phi) + sin (part->phi));

	    vertices[0] = part->x - offB;
	    vertices[1] = part->y - offA;
	    vertices[2] = 0;

	    vertices[3] = part->x - offA;
	    vertices[4] = part->y + offB;
	    vertices[5] = 0;

	    vertices[6] = part->x + offB;
	    vertices[7] = part->y + offA;
	    vertices[8] = 0;

	    vertices[9]  = part->x + offA;
	    vertices[10] = part->y - offB;
	    vertices[11] = 0;

	    vertices += 12;

	    memcpy (coords, cornerCoords, cornersSize);

	    coords += 8;

	    colors[0] = part->c[0];
	    colors[1] = part->c[1];
	    colors[2] = part->c[2];

	    if (part->t > ps->tnew)		//New particles start at a == 1
		colors[3] = part->a + (1. - part->a) * (part->t - ps->tnew)
					/ (1. - ps->tnew);
	    else if (part->t < ps->told)	//Old particles fade to a = 0
		colors[3] = part->a * part->t / ps->told;
	    else				//The others have their own a
		colors[3] = part->a;

	    memcpy (colors + 4, colors, colorSize);
	    memcpy (colors + 8, colors, colorSize);
	    memcpy (colors + 12, colors, colorSize);

	    colors += 16;

	    if (ps->darken > 0)
	    {
		dcolors[0] = colors[0];
		dcolors[1] = colors[1];
		dcolors[2] = colors[2];
		dcolors[3] = colors[3] * ps->darken;
		memcpy (dcolors + 4, dcolors, colorSize);
		memcpy (dcolors + 8, dcolors, colorSize);
		memcpy (dcolors + 12, dcolors, colorSize);

		dcolors += 16;
	    }
	}
    }

    glEnableClientState (GL_COLOR_ARRAY);

    glTexCoordPointer (2, GL_FLOAT, 2 * sizeof (GLfloat), ps->coords_cache);
    glVertexPointer (3, GL_FLOAT, 3 * sizeof (GLfloat), ps->vertices_cache);

    // darken the background
    if (ps->darken > 0)
    {
	glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
	glColorPointer (4, GL_FLOAT, 4 * sizeof (GLfloat), ps->dcolors_cache);
	glDrawArrays (GL_QUADS, 0, numActive);
    }
    // draw particles
    glBlendFunc (GL_SRC_ALPHA, ps->blendMode);

    glColorPointer (4, GL_FLOAT, 4 * sizeof (GLfloat), ps->colors_cache);

    glDrawArrays (GL_QUADS, 0, numActive);

    glDisableClientState (GL_COLOR_ARRAY);

    glPopMatrix ();
    glColor4usv (defaultColor);
    screenTexEnvMode (s, GL_REPLACE);
    glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glDisable (GL_TEXTURE_2D);
    glDisable (GL_BLEND);
}
static void
beginRendering (SnowScreen *ss,
		CompScreen *s)
{
    if (firefliesGetUseBlending (s->display))
	glEnable (GL_BLEND);

    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    if (ss->displayListNeedsUpdate)
    {
	setupDisplayList (ss);
	ss->displayListNeedsUpdate = FALSE;
    }

    glColor4f (1.0, 1.0, 1.0, 1.0);
    if (ss->snowTexturesLoaded && firefliesGetUseTextures (s->display))
    {
	int j;

	for (j = 0; j < ss->snowTexturesLoaded; j++)
	{
	    SnowFlake *snowFlake = ss->allSnowFlakes;
	    int       i, numFlakes = firefliesGetNumSnowflakes (s->display);
	   // Bool      snowRotate = firefliesGetSnowRotation (s->display);

	    enableTexture (ss->s, &ss->snowTex[j].tex,
			   COMP_TEXTURE_FILTER_GOOD);

	    for (i = 0; i < numFlakes; i++)
	    {
		glColor4f (1.0, 1.0, 1.0, ss->allSnowFlakes[i].glowAlpha);
		if (snowFlake->tex == &ss->snowTex[j])
		{
		    glTranslatef (snowFlake->x, snowFlake->y, snowFlake->z);
		    //if (snowRotate)
			//glRotatef (snowFlake->ra, 0, 0, 1);
		    glCallList (ss->snowTex[j].dList);
		    //if (snowRotate)
			//glRotatef (-snowFlake->ra, 0, 0, 1);
		    glTranslatef (-snowFlake->x, -snowFlake->y, -snowFlake->z);
		}
		snowFlake++;
	    }
	    disableTexture (ss->s, &ss->snowTex[j].tex);
	}
    }
    else
    {
	SnowFlake *snowFlake = ss->allSnowFlakes;
	int       i, numFlakes = firefliesGetNumSnowflakes (s->display);

	for (i = 0; i < numFlakes; i++)
	{
	    glTranslatef (snowFlake->x, snowFlake->y, snowFlake->z);
	    glRotatef (snowFlake->ra, 0, 0, 1);
	    glCallList (ss->displayList);
	    glRotatef (-snowFlake->ra, 0, 0, 1);
	    glTranslatef (-snowFlake->x, -snowFlake->y, -snowFlake->z);
	    snowFlake++;
	}
    }

    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    if (firefliesGetUseBlending (s->display))
    {
	glDisable (GL_BLEND);
	glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    }
}
Ejemplo n.º 8
0
Archivo: box.cpp Proyecto: yvd/MusicBox
void box()
{
	comp = glGenLists(1);
	glNewList(comp,GL_COMPILE);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
	glMaterialfv(GL_FRONT, GL_AMBIENT, white);
	glMaterialfv(GL_FRONT, GL_SPECULAR, white);
	glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
	char t1[] = "./textures/w3.bmp";
	char t2[] = "./textures/w2.bmp";
	texture1 = textureloader(t1);
	texture2 = textureloader(t2);
	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glBindTexture(GL_TEXTURE_2D, texture1);
	
	//front side
	glBegin(GL_POLYGON);
	glNormal3d(0,0,-1);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(  0.4, 0.2, -0.2 );
	glTexCoord2f(1.0, 0.0);
	glVertex3f(  0.4,  -0.2, -0.2 );
	glTexCoord2f(0.0, 0.0);
	glVertex3f( -0.4,  -0.2, -0.2 );
	glTexCoord2f(0.0, 1.0);
	glVertex3f( -0.4, 0.2, -0.2 );
	glEnd();
	 
	//right side
	glBegin(GL_POLYGON);
	glNormal3d(1,0,0);
	glTexCoord2f(1.0, 1.0);
	glVertex3f( 0.4, 0.2,  0.2 );
	glTexCoord2f(1.0, 0.0);
	glVertex3f( 0.4, -0.2, 0.2 );
	glTexCoord2f(0.0, 0.0);
	glVertex3f( 0.4,  -0.2, -0.2 );
	glTexCoord2f(0.0, 1.0);
	glVertex3f( 0.4,  0.2,  -0.2 );
	glEnd();
	 
	// left side
	glBegin(GL_POLYGON);
	glNormal3d(-1,0,0);
	glTexCoord2f(1.0, 1.0);
	glVertex3f( -0.4, 0.2, -0.2 );
	glTexCoord2f(1.0, 0.0);
	glVertex3f( -0.4, -0.2,  -0.2 );
	glTexCoord2f(0.0, 0.0);
	glVertex3f( -0.4,  -0.2,  0.2 );
	glTexCoord2f(0.0, 1.0);
	glVertex3f( -0.4,  0.2, 0.2 );
	
	glEnd();
	 
	// backside
	glBegin(GL_POLYGON);
	glNormal3d(0,0,1);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(  -0.4, 0.2,  0.2 );
	glTexCoord2f(1.0, 0.0);
	glVertex3f( -0.4, -0.2,  0.2 );
	glTexCoord2f(0.0, 0.0);
	glVertex3f( 0.4, -0.2, 0.2 );
	glTexCoord2f(0.0, 1.0);
	glVertex3f(  0.4, 0.2, 0.2 );
	glEnd();
	glEndList();
	// bottom 
	base = glGenLists(1);
	glNewList(base,GL_COMPILE);
	glBegin(GL_POLYGON);
	glNormal3d(0,-1,0);
	glTexCoord2f(1.0, 1.0);
	glVertex3f( 0.4, -0.2,  -0.2 );
	glTexCoord2f(1.0, 0.0);
	glVertex3f( 0.4, -0.2, 0.2 );
	glTexCoord2f(0.0, 0.0);
	glVertex3f(  -0.4, -0.2, 0.2 );
	glTexCoord2f(0.0, 1.0);
	glVertex3f( -0.4, -0.2, -0.2 );
	glEnd();
	glEndList();

	rot_floor = glGenLists(1);
	glNewList(rot_floor, GL_COMPILE);
	drawBox(0.2,GL_QUADS);
	glEndList();
	// Lid 
	l = glGenLists(1);
	glNewList(l,GL_COMPILE);
	glBegin(GL_POLYGON);
	glNormal3d(0,1,0);
	glTexCoord2f(1.0, 1.0);
	glVertex3f( 0.4, 0,  0 );
	glTexCoord2f(1.0, 0.0);
	glVertex3f( 0.4, 0, -0.4 );
	glTexCoord2f(0.0, 0.0);
	glVertex3f(  -0.4, 0, -0.4 );
	glTexCoord2f(0.0, 1.0);
	glVertex3f( -0.4, 0, 0 );
	glEnd();
	glEndList();
}
Ejemplo n.º 9
0
void QGLWidgetTest::DrawTriangles(const GDynArray< GPoint<GDouble, 2> >& Points,
								  const GDynArray<GULong>& Indexes) {

	GUInt32 i, j = Indexes.size();
	GPoint<GDouble, 2> a, b, c;
	GPoint<GDouble, 3> col;
	GLfloat texPlaneGen[4];

	if (gFillMode == 2 || gFillMode == 3) {
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture);
		glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
		glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
		glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
		glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		texPlaneGen[0] = 0.05f;
		texPlaneGen[1] = 0;
		texPlaneGen[2] = 0;
		texPlaneGen[3] = 0;
		glTexGenfv(GL_S, GL_EYE_PLANE, texPlaneGen);
		texPlaneGen[0] = 0;
		texPlaneGen[1] = 0.05f;
		texPlaneGen[2] = 0;
		texPlaneGen[3] = 0;
		glTexGenfv(GL_T, GL_EYE_PLANE, texPlaneGen);
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
	}

	// debug stuff
	glBegin(GL_LINES);
	glColor3f(0.0f, 0.2f, 0.4f);
	a[G_X] = -2;
	for (i = 0; i < 21; i++) {
		glVertex3d(a[G_X], 0.0f, 1.0f);
		glVertex3d(a[G_X], 16.0f, 1.0f);
		a[G_X] += 1.0;
	}
	a[G_Y] = 0;
	for (i = 0; i < 17; i++) {
		glVertex3d(-2, a[G_Y], 1.0f);
		glVertex3d(18.0, a[G_Y], 1.0f);
		a[G_Y] += 1.0;
	}

	glColor3f(0.6f, 0.0f, 0.3f);
	a[G_X] = -1.5;
	for (i = 0; i < 20; i++) {
		glVertex3d(a[G_X], 0.0f, 1.0f);
		glVertex3d(a[G_X], 16.0f, 1.0f);
		a[G_X] += 1.0;
	}
	a[G_Y] = 0.5;
	for (i = 0; i < 16; i++) {
		glVertex3d(-2, a[G_Y], 1.0f);
		glVertex3d(18.0, a[G_Y], 1.0f);
		a[G_Y] += 1.0;
	}
	glEnd();


	glEnable(GL_BLEND);
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
	glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
	glBlendFunc(GL_ONE, GL_ONE);

	glBegin(GL_TRIANGLES);
	if (gFillMode == 0) {
		glColor3f(0.2f, 0.2f, 0.2f);
		for (i = 0; i < j; i+=3) {
			a = Points[Indexes[i]];
			b = Points[Indexes[i + 1]];
			c = Points[Indexes[i + 2]];
			glVertex3d(a[G_X], a[G_Y], 1.0);
			glVertex3d(b[G_X], b[G_Y], 1.0);
			glVertex3d(c[G_X], c[G_Y], 1.0);
		}
	}
	else
	if (gFillMode == 1) {
		GPoint<GDouble, 3> col1(0.0f, 0.1f, 0.2f);
		GPoint<GDouble, 3> col2(0.3f, 0.2f, 1.0f);
		for (i = 0; i < j; i+=3) {
			a = Points[Indexes[i]];
			b = Points[Indexes[i + 1]];
			c = Points[Indexes[i + 2]];
			col = GMath::BarycentricConvexSum(a[G_X] + 1.0, col1, 18.0 - a[G_X], col2);
			glColor3d(col[0], col[1], col[2]);
			glVertex3d(a[G_X], a[G_Y], 1.0);
			col = GMath::BarycentricConvexSum(b[G_X] + 1.0, col1, 18.0 - b[G_X], col2);
			glColor3d(col[0], col[1], col[2]);
			glVertex3d(b[G_X], b[G_Y], 1.0);
			col = GMath::BarycentricConvexSum(c[G_X] + 1.0, col1, 18.0 - c[G_X], col2);
			glColor3d(col[0], col[1], col[2]);
			glVertex3d(c[G_X], c[G_Y], 1.0);
		}
	}
	else
	if (gFillMode == 2) {
		glColor3f(1.0f, 1.0f, 1.0f);
		for (i = 0; i < j; i+=3) {
			a = Points[Indexes[i]];
			b = Points[Indexes[i + 1]];
			c = Points[Indexes[i + 2]];
			glVertex3d(a[G_X], a[G_Y], 1.0);
			glVertex3d(b[G_X], b[G_Y], 1.0);
			glVertex3d(c[G_X], c[G_Y], 1.0);
		}
	}
	glEnd();

	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);
	glDisable(GL_TEXTURE_2D);
	if (!gWireFrame)
		return;

	glLineWidth(1.0f);
	glBegin(GL_LINES);
	glColor3f(0.0f, 0.0f, 0.0f);
	for (i = 0; i < j; i+=3) {
		a = Points[Indexes[i]];
		b = Points[Indexes[i + 1]];
		c = Points[Indexes[i + 2]];
		glVertex3d(a[G_X], a[G_Y], 1.0f);
		glVertex3d(b[G_X], b[G_Y], 1.0f);
		glVertex3d(a[G_X], a[G_Y], 1.0f);
		glVertex3d(c[G_X], c[G_Y], 1.0f);
		glVertex3d(b[G_X], b[G_Y], 1.0f);
		glVertex3d(c[G_X], c[G_Y], 1.0f);
	}
	glEnd();

	GString s, s2;
	j = Points.size();
	glColor3f(0.1f, 0.1f, 0.1f);
	for (i = 0; i < j; ++i) {
		a = Points[i];
		s = StrUtils::ToString(a, ";", "%5.2f");
		s = StrUtils::Purge(s, " ");
		glRasterPos2d(a[G_X], a[G_Y]);
		glMyPrint(StrUtils::ToAscii(s));
	}
}
Ejemplo n.º 10
0
void gl_init(void)
{
  ilInit();

  float fogColor[]={0.1,0.1,0.1,1};

  // setup perpective
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(FOV,(GLfloat)RESX/(GLfloat)RESY,1,16384);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  // setup shade model
  glShadeModel(GL_SMOOTH);

  // setup depth buffer
  glClearDepth(1.0);
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);

  // setup face culling
  glFrontFace(GL_CCW);
  glEnable(GL_CULL_FACE);

  
  // setup vertex arrays
  glEnableClientState(GL_VERTEX_ARRAY);
//  glVertexPointer(3,GL_FLOAT,sizeof(vertex_t),vertex[0].coordinate);
//  glClientActiveTextureARB(GL_TEXTURE0_ARB); 
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//  glTexCoordPointer(2,GL_FLOAT,sizeof(vertex_t),vertex[0].texCoordinate);
//  glClientActiveTextureARB(GL_TEXTURE1_ARB); 
//  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//  glTexCoordPointer(2 ,GL_FLOAT,sizeof(vertex_t),vertex[0].lmapCoordinate);
  glEnableClientState(GL_NORMAL_ARRAY);
 

  // set up texturing
  // glActiveTextureARB(GL_TEXTURE0_ARB);
  glEnable(GL_TEXTURE_2D);
  glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
  // glActiveTextureARB(GL_TEXTURE1_ARB);
  // glEnable(GL_TEXTURE_2D);
  // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

  // setup lights
  GLfloat lmodel_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  glEnable(GL_LIGHTING);
  glEnable(GL_NORMALIZE);
//  glEnable(GL_RESCALE_NORMAL);


  // set up fog
  glFogi(GL_FOG_MODE,GL_EXP2);
  glFogfv(GL_FOG_COLOR,fogColor);
  glFogf(GL_FOG_DENSITY,0.001);
  glHint(GL_FOG_HINT,GL_NICEST);
  if(FOG) glEnable(GL_FOG);

  // rotate textures to compensate for different origin per image type.
  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
  glRotatef(180, 1, 0, 0);

  // reset camera
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // clear and update frame buffer
  glClearColor(0,0,0,0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);	
  glFlush();
  SDL_GL_SwapWindow(main_window);
}
Ejemplo n.º 11
0
int LoadBitmap(char *filename)
{
    FILE * file;
    char temp;
    long i;

    // own version of BITMAPINFOHEADER from windows.h for Linux compile
    struct {
      int biWidth;
      int biHeight;
      short int biPlanes;
      unsigned short int biBitCount;
      unsigned char *data;
    } infoheader;

    GLuint num_texture;

    if( (file = fopen(filename, "rb"))==NULL) return (-1); // Open the file for reading

    fseek(file, 18, SEEK_CUR);  /* start reading width & height */
    fread(&infoheader.biWidth, sizeof(int), 1, file);

    fread(&infoheader.biHeight, sizeof(int), 1, file);

    fread(&infoheader.biPlanes, sizeof(short int), 1, file);
    if (infoheader.biPlanes != 1) {
      printf("Planes from %s is not 1: %u\n", filename, infoheader.biPlanes);
      return 0;
    }

    // read the bpp
    fread(&infoheader.biBitCount, sizeof(unsigned short int), 1, file);
    if (infoheader.biBitCount != 24) {
      printf("Bpp from %s is not 24: %d\n", filename, infoheader.biBitCount);
      return 0;
    }

    fseek(file, 24, SEEK_CUR);

    // read the data
    if(infoheader.biWidth<0){
      infoheader.biWidth = -infoheader.biWidth;
    }
    if(infoheader.biHeight<0){
      infoheader.biHeight = -infoheader.biHeight;
    }
    infoheader.data = (unsigned char *) malloc(infoheader.biWidth * infoheader.biHeight * 3);
    if (infoheader.data == NULL) {
      printf("Error allocating memory for color-corrected image data\n");
      return 0;
    }

    if ((i = fread(infoheader.data, infoheader.biWidth * infoheader.biHeight * 3, 1, file)) != 1) {
      printf("Error reading image data from %s.\n", filename);
      return 0;
    }

    for (i=0; i<(infoheader.biWidth * infoheader.biHeight * 3); i+=3) { // reverse all of the colors. (bgr -> rgb)
      temp = infoheader.data[i];
      infoheader.data[i] = infoheader.data[i+2];
      infoheader.data[i+2] = temp;
    }


    fclose(file); // Closes the file stream

    glGenTextures(1, &num_texture);
    glBindTexture(GL_TEXTURE_2D, num_texture); // Bind the ID texture specified by the 2nd parameter

    // The next commands sets the texture parameters
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produces better results)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //The minifying function

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    // Finally we define the 2d texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, infoheader.biWidth, infoheader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, infoheader.data);

    // And create 2d mipmaps for the minifying function
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, infoheader.biWidth, infoheader.biHeight, GL_RGB, GL_UNSIGNED_BYTE, infoheader.data);
    
    free(infoheader.data); // Free the memory we used to load the texture

    return (num_texture); // Returns the current texture OpenGL ID
}
Ejemplo n.º 12
0
void R_DrawParticles (void)
{
	particle_t		*p, *kill;
	int				i;
	float			vel0, vel1, vel2;
	vec3_t			save_org;

#ifdef GLQUAKE
	float			scale;

	GL_Bind(particletexture);
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glBegin (GL_TRIANGLES);

	VectorScale (vup, 1.5, r_pup);
	VectorScale (vright, 1.5, r_pright);
#else

	VectorScale (vright, xscaleshrink, r_pright);
	VectorScale (vup, yscaleshrink, r_pup);
	VectorCopy (vpn, r_ppn);
#endif

	for ( ;; ) 
	{
		kill = active_particles;
		if (kill && kill->die < cl.time)
		{
			active_particles = kill->next;
			kill->next = free_particles;
			free_particles = kill;
			continue;
		}
		break;
	}

	for (p=active_particles ; p ; p=p->next)
	{
		for ( ;; )
		{
			kill = p->next;
			if (kill && kill->die < cl.time)
			{
				p->next = kill->next;
				kill->next = free_particles;
				free_particles = kill;
				continue;
			}
			break;
		}
		
		if (p->type==pt_rain)
		{
#ifdef GLQUAKE
			// hack a scale up to keep particles from disapearing
			scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1]
				+ (p->org[2] - r_origin[2])*vpn[2];
			if (scale < 20)
				scale = 1;
			else
				scale = 1 + scale * 0.004;
			if (p->color <= 255)
				glColor3ubv ((byte *)&d_8to24table[(int)p->color]);
			else
				glColor4ubv ((byte *)&d_8to24TranslucentTable[(int)p->color-256]);
			
			//fixme: need rain texture
			glTexCoord2f (1,0);
			glVertex3fv (p->org);
			glTexCoord2f (1,0.5);
			glVertex3f (p->org[0] + r_pup[0]*scale, p->org[1] + r_pup[1]*scale, p->org[2] + r_pup[2]*scale);
			glTexCoord2f (0.5,0);
			glVertex3f (p->org[0] + r_pright[0]*scale, p->org[1] + r_pright[1]*scale, p->org[2] + r_pright[2]*scale);
#else
			VectorCopy(p->org,save_org);

			vel0 = p->vel[0]*.001;
			vel1 = p->vel[1]*.001;
			vel2 = p->vel[2]*.001;

			for(i=0;i<4;i++)
			{
				D_DrawParticle(p);
				p->org[0] += vel0;
				p->org[1] += vel1;
				p->org[2] += vel2;
 			}
			D_DrawParticle(p);

			VectorCopy(save_org,p->org);//Restore origin
#endif
		}
		else if (p->type==pt_snow)
		{
#ifdef GLQUAKE
//IDEA: Put a snowflake texture on two-sided poly
//texture comes from glrmisc.c: R_InitParticleTexture 
			scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1]
				+ (p->org[2] - r_origin[2])*vpn[2];
			if (scale < 20)
				scale = p->count/10;	
			else
				scale = p->count/10 + scale * 0.004;

			if (p->color <= 255)
				glColor3ubv ((byte *)&d_8to24table[(int)p->color]);
			else
				glColor4ubv ((byte *)&d_8to24TranslucentTable[(int)p->color-256]);
	
			if(p->count>=69)
				glTexCoord2f (1,1);//happy snow!- bottom right
			else if(p->count>=40)	
				glTexCoord2f (0,0);	//normal snow - top left
			else if(p->count>=30)
				glTexCoord2f (0,1);	//bottom left
			else
				glTexCoord2f (1,0);	//top right

			glVertex3fv (p->org);
			if(p->count>=69)
				glTexCoord2f (1,.18);//top right
			else if(p->count>=40)	
				glTexCoord2f (.815,0);//top right
			else if(p->count>=30)
				glTexCoord2f (0.5,1);//bottom middle
			else
				glTexCoord2f (1,0.5);//middle right

			glVertex3f (p->org[0] + r_pup[0]*scale, p->org[1] + r_pup[1]*scale, p->org[2] + r_pup[2]*scale);

			if(p->count>=69)
				glTexCoord2f (.18,1);//bottom left
			else if(p->count>=40)	
				glTexCoord2f (0,.815);//bottom left
			else if(p->count>=30)
				glTexCoord2f (0,0.5);//left middle
			else
				glTexCoord2f (0.5,0);//middle top
			
			glVertex3f (p->org[0] + r_pright[0]*scale, p->org[1] + r_pright[1]*scale, p->org[2] + r_pright[2]*scale);
#else
			VectorCopy(p->org,save_org);
			D_DrawParticle (p);

			for(i=1;i<p->count;i++)
			{
				switch(i)
				{//FIXME:  More translucency on outside particles?
//				case 0:	//original
//					break;
				case 1:	//One to right
					p->org[0] = save_org[0] + vright[0];
					p->org[1] = save_org[1] + vright[1];
					p->org[2] = save_org[2] + vright[2];
					break;
				case 2: //One above
					p->org[0] = save_org[0] + vup[0];
					p->org[1] = save_org[1] + vup[1];
					p->org[2] = save_org[2] + vup[2];
					break;
				case 3:	//One to left
					p->org[0] = save_org[0] - vright[0];
					p->org[1] = save_org[1] - vright[1];
					p->org[2] = save_org[2] - vright[2];
					break;
				case 4:	//One below
					p->org[0] = save_org[0] - vup[0];
					p->org[1] = save_org[1] - vup[1];					
					p->org[2] = save_org[2] - vup[2];
					break;
				default:
				   Con_Printf ("count too big!\n");
					break;
				}
				D_DrawParticle (p);
			}
			VectorCopy(save_org,p->org);//Restore origin
#endif
		}
		else
		{
#ifdef GLQUAKE
			// hack a scale up to keep particles from disapearing
			scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1]
				+ (p->org[2] - r_origin[2])*vpn[2];
			if (scale < 20)
				scale = 1;
			else
				scale = 1 + scale * 0.004;
			if (p->color <= 255)
				glColor3ubv ((byte *)&d_8to24table[(int)p->color]);
			else
				glColor4ubv ((byte *)&d_8to24TranslucentTable[(int)p->color-256]);
			glTexCoord2f (1,0);
			glVertex3fv (p->org);
			glTexCoord2f (1,0.5);
			glVertex3f (p->org[0] + r_pup[0]*scale, p->org[1] + r_pup[1]*scale, p->org[2] + r_pup[2]*scale);
			glTexCoord2f (0.5,0);
			glVertex3f (p->org[0] + r_pright[0]*scale, p->org[1] + r_pright[1]*scale, p->org[2] + r_pright[2]*scale);
#else
			D_DrawParticle (p);
#endif
		}
	}

#ifdef GLQUAKE
	glEnd ();
	glDisable (GL_BLEND);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif
}
Ejemplo n.º 13
0
void PauseMenuMode::Render() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glMatrixMode(GL_MODELVIEW);

   // draw background
   glPushMatrix();
   glLoadIdentity();

   glActiveTexture(GL_TEXTURE1_ARB);
   glEnable(GL_TEXTURE_2D);

   glActiveTexture(GL_TEXTURE0_ARB);
   glBindTexture(GL_TEXTURE_2D, mBackgroundTexture);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

   glActiveTexture(GL_TEXTURE1_ARB);
   glBindTexture(GL_TEXTURE_2D, mBackgroundLightmap.TextureID);
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

   glBegin(GL_QUADS);
      glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0, 0.0);
      glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0, 0.0);
      glVertex2i(0, mGameWindow->GetHeight());

      glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0, 0.0);
      glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0, 0.0);
      glVertex2i(mGameWindow->GetWidth(), mGameWindow->GetHeight());

      glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0, 1.0);
      glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0, 1.0);
      glVertex2i(mGameWindow->GetWidth(), 0);

      glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0, 1.0);
      glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0, 1.0);
      glVertex2f(0, 0);
   glEnd();
   glPopMatrix();

   glActiveTexture(GL_TEXTURE1_ARB);
   glDisable(GL_TEXTURE_2D);

   glActiveTexture(GL_TEXTURE0_ARB);

   // draw menu back
   glPushMatrix();
   glLoadIdentity();

   int texW = (int)floor(mMenuTexture.Width * (mGameWindow->GetWidth() / 1600.0f));
   int texH = (int)floor(mMenuTexture.Height * (mGameWindow->GetHeight() / 1200.0f));

   glTranslatef(mGameWindow->GetWidth() / 2.0f, mGameWindow->GetHeight() / 2.0f, 0);
   glBindTexture(GL_TEXTURE_2D, mMenuTexture.TextureID);
   glBegin(GL_QUADS);
      glTexCoord2i(0, 0);
      glVertex2f(-texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 0);
      glVertex2f(texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 1);
      glVertex2f(texW / 2.0f, -texH / 2.0f);

      glTexCoord2i(0, 1);
      glVertex2f(-texW / 2.0f, -texH / 2.0f);
   glEnd();
   glPopMatrix();

   // draw resume button
   glPushMatrix();
   glLoadIdentity();

   texW = (int)floor(mButtons[BTN_RESUME].mTexture.Width * 
    (mGameWindow->GetWidth() / 1600.0f));
   texH = (int)floor(mButtons[BTN_RESUME].mTexture.Height *
    (mGameWindow->GetHeight() / 1200.0f));

   glTranslatef(mGameWindow->GetWidth() / 2.0f, 2 * mGameWindow->GetHeight() / 6.0f, 0);
   if (mButtonPressed == BTN_RESUME)
      glBindTexture(GL_TEXTURE_2D, 
       mButtons[BTN_RESUME].mPressedTexture.TextureID);
   else
      glBindTexture(GL_TEXTURE_2D, 
       mButtons[BTN_RESUME].mTexture.TextureID);
   glBegin(GL_QUADS);
      glTexCoord2i(0, 0);
      glVertex2f(-texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 0);
      glVertex2f(texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 1);
      glVertex2f(texW / 2.0f, -texH / 2.0f);

      glTexCoord2i(0, 1);
      glVertex2f(-texW / 2.0f, -texH / 2.0f);
   glEnd();
   glPopMatrix();

   // draw options button
   glPushMatrix();
   glLoadIdentity();

   texW = (int)floor(mButtons[BTN_OPTIONS].mTexture.Width * 
    (mGameWindow->GetWidth() / 1600.0));
   texH = (int)floor(mButtons[BTN_OPTIONS].mTexture.Height *
    (mGameWindow->GetHeight() / 1200.0));

   glTranslatef(mGameWindow->GetWidth() / 2.0f, 3 * mGameWindow->GetHeight() / 6.0f, 0);
   if (mButtonPressed == BTN_OPTIONS)
      glBindTexture(GL_TEXTURE_2D, 
       mButtons[BTN_OPTIONS].mPressedTexture.TextureID);
   else
      glBindTexture(GL_TEXTURE_2D, 
       mButtons[BTN_OPTIONS].mTexture.TextureID);
   glBegin(GL_QUADS);
      glTexCoord2i(0, 0);
      glVertex2f(-texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 0);
      glVertex2f(texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 1);
      glVertex2f(texW / 2.0f, -texH / 2.0f);

      glTexCoord2i(0, 1);
      glVertex2f(-texW / 2.0f, -texH / 2.0f);
   glEnd();
   glPopMatrix();

   // draw resume button
   glPushMatrix();
   glLoadIdentity();

   texW = (int)floor(mButtons[BTN_QUIT].mTexture.Width * 
    (mGameWindow->GetWidth() / 1600.0f));
   texH = (int)floor(mButtons[BTN_QUIT].mTexture.Height *
    (mGameWindow->GetHeight() / 1200.0f));

   glTranslatef(mGameWindow->GetWidth() / 2.0f, 4 * mGameWindow->GetHeight() / 6.0f, 0);
   if (mButtonPressed == BTN_QUIT)
      glBindTexture(GL_TEXTURE_2D, 
       mButtons[BTN_QUIT].mPressedTexture.TextureID);
   else
      glBindTexture(GL_TEXTURE_2D, 
       mButtons[BTN_QUIT].mTexture.TextureID);
   glBegin(GL_QUADS);
      glTexCoord2i(0, 0);
      glVertex2f(-texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 0);
      glVertex2f(texW / 2.0f, texH / 2.0f);

      glTexCoord2i(1, 1);
      glVertex2f(texW / 2.0f, -texH / 2.0f);

      glTexCoord2i(0, 1);
      glVertex2f(-texW / 2.0f, -texH / 2.0f);
   glEnd();
   glPopMatrix();

   SDL_GL_SwapBuffers();
}
Ejemplo n.º 14
0
void CSkybox::Render(float cameraX, float cameraY, float cameraZ)
{
	glPushMatrix();

	// Move the skybox so that it's centered on the camera.
	glTranslatef(cameraX, cameraY, cameraZ);

	glPushAttrib(GL_FOG_BIT | GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT);
	glDisable(GL_DEPTH_TEST);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	// Top
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_TOP]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_size, m_size, -m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(m_size, m_size, -m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(m_size, m_size, m_size);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_size, m_size, m_size);
	glEnd();

	GLfloat fog_color[4] = {0.2f, 0.2f, 0.2f, 0.8};
	// skybox origin should be same as camera position
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE, GL_EXP2);
	glFogf(GL_FOG_START, 10.0);
	glFogf(GL_FOG_END, 1000.0);
	glFogfv(GL_FOG_COLOR, fog_color);
	glFogf(GL_FOG_DENSITY, 0.3);
	// Bottom
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_BOTTOM]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(m_size, -m_size, -m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_size, -m_size, -m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(m_size, -m_size, m_size);
	glEnd();
	glDisable(GL_FOG);

	// Front
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_FRONT]);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_size, -m_size, -m_size);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(m_size, -m_size, -m_size);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(m_size, m_size, -m_size);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_size, m_size, -m_size);
	glEnd();

	// Back
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_BACK]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_size, m_size, m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(m_size, m_size, m_size);
	glEnd();

	// Right
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_RIGHT]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(m_size, m_size, m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(m_size, m_size, -m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(m_size, -m_size, -m_size);
	glEnd();

	// Left
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_LEFT]);
	glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_size, -m_size, -m_size);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_size, m_size, -m_size); 
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_size, m_size, m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_size, -m_size, m_size);
	glEnd();

	glPopAttrib();
	glEndList();
	glPopMatrix();
}
Ejemplo n.º 15
0
/* Create a texture in OpenGL.  First an image is loaded 
   and stored in a raster buffer, then it's  */
static void Create_Texture(ModeInfo *mi, const char *filename)
{
  int height, width;
  GLubyte *image;
  int format;

  if ( !strncmp(filename, "BUILTIN", 7))
    image = Generate_Image(&width, &height, &format);
  else
    {
      XImage *ximage = xpm_file_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi),
                                           MI_COLORMAP (mi), filename);
      image  = (GLubyte *) ximage->data;
      width  = ximage->width;
      height = ximage->height;
      format = GL_RGBA;
    }

  /* GL_MODULATE or GL_DECAL depending on what you want */
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  /* perhaps we can edge a bit more speed at the expense of quality */
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

  if (do_tex_qual) {
	/* with texture_quality, the min and mag filters look *much* nice but are *much* slower */
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  }
  else {
	/* default is to do it quick and dirty */
	/* if you have mipmaps turned on, but not texture quality, nothing will happen! */
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  }

  /* mipmaps make the image look much nicer */
  if (do_mipmap)
    {
      int status;
      clear_gl_error();
      status = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, format,
                                 GL_UNSIGNED_BYTE, image);
      if (status)
        {
          const char *s = (char *) gluErrorString (status);
          fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n",
                   progname, width, height,
                   (s ? s : "(unknown)"));
          exit (1);
        }
      check_gl_error("mipmapping");
    }
  else
    {
      clear_gl_error();
      glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0,
                   format, GL_UNSIGNED_BYTE, image);
      check_gl_error("texture");
    }
}
Ejemplo n.º 16
0
/*
=================
R_DrawAliasModel -- johnfitz -- almost completely rewritten
=================
*/
void R_DrawAliasModel (entity_t *e)
{
	aliashdr_t	*paliashdr;
	int			i, anim;
	gltexture_t	*tx, *fb;
	lerpdata_t	lerpdata;

	//
	// setup pose/lerp data -- do it first so we don't miss updates due to culling
	//
	paliashdr = (aliashdr_t *)Mod_Extradata (e->model);
	R_SetupAliasFrame (paliashdr, e->frame, &lerpdata);
	R_SetupEntityTransform (e, &lerpdata);

	//
	// cull it
	//
	if (R_CullModelForEntity(e))
		return;

	//
	// transform it
	//
    glPushMatrix ();
	R_RotateForEntity (lerpdata.origin, lerpdata.angles);
	glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
	glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);

	//
	// random stuff
	//
	if (gl_smoothmodels.value && !r_drawflat_cheatsafe)
		glShadeModel (GL_SMOOTH);
	if (gl_affinemodels.value)
		glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
	overbright = gl_overbright_models.value;
	shading = true;

	//
	// set up for alpha blending
	//
	if (r_drawflat_cheatsafe || r_lightmap_cheatsafe) //no alpha in drawflat or lightmap mode
		entalpha = 1;
	else
		entalpha = ENTALPHA_DECODE(e->alpha);
	if (entalpha == 0)
		goto cleanup;
	if (entalpha < 1)
	{
		if (!gl_texture_env_combine) overbright = false; //overbright can't be done in a single pass without combiners
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);
	}

	//
	// set up lighting
	//
	rs_aliaspolys += paliashdr->numtris;
	R_SetupAliasLighting (e);

	//
	// set up textures
	//
	GL_DisableMultitexture();
	anim = (int)(cl.time*10) & 3;
	tx = paliashdr->gltextures[e->skinnum][anim];
	fb = paliashdr->fbtextures[e->skinnum][anim];
	if (e->colormap != vid.colormap && !gl_nocolors.value)
	{
		i = e - cl_entities;
		if (i >= 1 && i<=cl.maxclients /* && !strcmp (currententity->model->name, "progs/player.mdl") */)
		    tx = playertextures[i - 1];
	}
	if (!gl_fullbrights.value)
		fb = NULL;

	//
	// draw it
	//
	if (r_drawflat_cheatsafe)
	{
		glDisable (GL_TEXTURE_2D);
		GL_DrawAliasFrame (paliashdr, lerpdata);
		glEnable (GL_TEXTURE_2D);
		srand((int) (cl.time * 1000)); //restore randomness
	}
	else if (r_fullbright_cheatsafe)
	{
		GL_Bind (tx);
		shading = false;
		glColor4f(1,1,1,entalpha);
		GL_DrawAliasFrame (paliashdr, lerpdata);
		if (fb)
		{
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			GL_Bind(fb);
			glEnable(GL_BLEND);
			glBlendFunc (GL_ONE, GL_ONE);
			glDepthMask(GL_FALSE);
			glColor3f(entalpha,entalpha,entalpha);
			Fog_StartAdditive ();
			GL_DrawAliasFrame (paliashdr, lerpdata);
			Fog_StopAdditive ();
			glDepthMask(GL_TRUE);
			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glDisable(GL_BLEND);
		}
	}
	else if (r_lightmap_cheatsafe)
	{
		glDisable (GL_TEXTURE_2D);
		shading = false;
		glColor3f(1,1,1);
		GL_DrawAliasFrame (paliashdr, lerpdata);
		glEnable (GL_TEXTURE_2D);
	}
	else if (overbright)
	{
		if  (gl_texture_env_combine && gl_mtexable && gl_texture_env_add && fb) //case 1: everything in one pass
		{
			GL_Bind (tx);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
			glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
			GL_EnableMultitexture(); // selects TEXTURE1
			GL_Bind (fb);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
			glEnable(GL_BLEND);
			GL_DrawAliasFrame (paliashdr, lerpdata);
			glDisable(GL_BLEND);
			GL_DisableMultitexture();
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		}
		else if (gl_texture_env_combine) //case 2: overbright in one pass, then fullbright pass
		{
		// first pass
			GL_Bind(tx);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
			glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2.0f);
			GL_DrawAliasFrame (paliashdr, lerpdata);
			glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.0f);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		// second pass
			if (fb)
			{
				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
				GL_Bind(fb);
				glEnable(GL_BLEND);
				glBlendFunc (GL_ONE, GL_ONE);
				glDepthMask(GL_FALSE);
				shading = false;
				glColor3f(entalpha,entalpha,entalpha);
				Fog_StartAdditive ();
				GL_DrawAliasFrame (paliashdr, lerpdata);
				Fog_StopAdditive ();
				glDepthMask(GL_TRUE);
				glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				glDisable(GL_BLEND);
				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			}
		}
		else //case 3: overbright in two passes, then fullbright pass
		{
		// first pass
			GL_Bind(tx);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			GL_DrawAliasFrame (paliashdr, lerpdata);
		// second pass -- additive with black fog, to double the object colors but not the fog color
			glEnable(GL_BLEND);
			glBlendFunc (GL_ONE, GL_ONE);
			glDepthMask(GL_FALSE);
			Fog_StartAdditive ();
			GL_DrawAliasFrame (paliashdr, lerpdata);
			Fog_StopAdditive ();
			glDepthMask(GL_TRUE);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glDisable(GL_BLEND);
		// third pass
			if (fb)
			{
				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
				GL_Bind(fb);
				glEnable(GL_BLEND);
				glBlendFunc (GL_ONE, GL_ONE);
				glDepthMask(GL_FALSE);
				shading = false;
				glColor3f(entalpha,entalpha,entalpha);
				Fog_StartAdditive ();
				GL_DrawAliasFrame (paliashdr, lerpdata);
				Fog_StopAdditive ();
				glDepthMask(GL_TRUE);
				glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				glDisable(GL_BLEND);
				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			}
		}
	}
	else
	{
		if (gl_mtexable && gl_texture_env_add && fb) //case 4: fullbright mask using multitexture
		{
			GL_DisableMultitexture(); // selects TEXTURE0
			GL_Bind (tx);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			GL_EnableMultitexture(); // selects TEXTURE1
			GL_Bind (fb);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
			glEnable(GL_BLEND);
			GL_DrawAliasFrame (paliashdr, lerpdata);
			glDisable(GL_BLEND);
			GL_DisableMultitexture();
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		}
		else //case 5: fullbright mask without multitexture
		{
		// first pass
			GL_Bind(tx);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			GL_DrawAliasFrame (paliashdr, lerpdata);
		// second pass
			if (fb)
			{
				GL_Bind(fb);
				glEnable(GL_BLEND);
				glBlendFunc (GL_ONE, GL_ONE);
				glDepthMask(GL_FALSE);
				shading = false;
				glColor3f(entalpha,entalpha,entalpha);
				Fog_StartAdditive ();
				GL_DrawAliasFrame (paliashdr, lerpdata);
				Fog_StopAdditive ();
				glDepthMask(GL_TRUE);
				glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				glDisable(GL_BLEND);
			}
		}
	}

cleanup:
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glShadeModel (GL_FLAT);
	glDepthMask(GL_TRUE);
	glDisable(GL_BLEND);
	glColor3f(1,1,1);
	glPopMatrix ();
}
Ejemplo n.º 17
0
__private_extern__ void initSaver(int width,int height,SolarWindsSaverSettings * inSettings)
{
    int i, j;
    float x,x2, y, temp;

    srand((unsigned)time(NULL));
    rand(); rand(); rand(); rand(); rand();

    // Window initialization

    glViewport(0,0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.0, float(width) / float(height), 1.0, 10000);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    if(!inSettings->dGeometry)
        glBlendFunc(GL_ONE, GL_ONE);
    else
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);  // Necessary for point and line smoothing (I don't know why)
    
    glEnable(GL_BLEND);

    if (glIsTexture(1))
    {
        GLuint tTex=1;
        
        glDeleteTextures(1, &tTex);
    }
    
    if(!inSettings->dGeometry)
    {
        // Init lights
        
        for(i=0; i<LIGHTSIZE; i++)
        {
            x = float(i - LIGHTSIZE / 2) / float(LIGHTSIZE / 2);
            
            x2=x*x;
            
            for(j=0; j<LIGHTSIZE; j++)
            {
                y = float(j - LIGHTSIZE / 2) / float(LIGHTSIZE / 2);

                temp = 1.0f - float(sqrt(x2 + (y * y)));

                if(temp > 1.0f)
                {
                    temp = 1.0f;
                }
                else
                {
                    if(temp < 0.0f)
                        temp = 0.0f;
                }
                
                inSettings->lightTexture[i][j] = (unsigned char) (255.0f * temp);
            }
        }
        
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 1);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, 1, LIGHTSIZE, LIGHTSIZE, 0,
                GL_LUMINANCE, GL_UNSIGNED_BYTE, inSettings->lightTexture);
        temp = 0.02f * float(inSettings->dSize);
        glNewList(1, GL_COMPILE);
            glBindTexture(GL_TEXTURE_2D, 1);
            glBegin(GL_TRIANGLE_STRIP);
                    glTexCoord2f(0.0f, 0.0f);
                    glVertex3f(-temp, -temp, 0.0f);
                    glTexCoord2f(1.0f, 0.0f);
                    glVertex3f(temp, -temp, 0.0f);
                    glTexCoord2f(0.0f, 1.0f);
                    glVertex3f(-temp, temp, 0.0f);
                    glTexCoord2f(1.0f, 1.0f);
                    glVertex3f(temp, temp, 0.0f);
            glEnd();
    
        glEndList();
    }
    else
    {
        glDisable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, 0);
        
        if(inSettings->dGeometry == 1)
        {  // init point smoothing
            glEnable(GL_POINT_SMOOTH);
            glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
        }
        else
        {
            if(inSettings->dGeometry == 2)
            {  // init line smoothing
                glEnable(GL_LINE_SMOOTH);
                glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
            }
        }
    }

    // Initialize surfaces
    
    inSettings->winds = new wind[inSettings->dWinds];
	
	for(i=0;i<inSettings->dWinds;i++)
	{
		inSettings->winds[i].initializeWithSetting(inSettings);
	}
}
Ejemplo n.º 18
0
static void
inittextures(void)
{
   GLenum gluerr;
   GLubyte tex[128][128][4];

   glGenTextures(1, &groundid);
   glBindTexture(GL_TEXTURE_2D, groundid);

   glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
   if (!LoadRGBMipmaps(DEMOS_DATA_DIR "s128.rgb", GL_RGB)) {
      fprintf(stderr, "Error reading a texture.\n");
      exit(-1);
   }

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
		   GL_LINEAR_MIPMAP_LINEAR);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

   glGenTextures(1, &treeid);
   glBindTexture(GL_TEXTURE_2D, treeid);

   if (1)
   {
      int w, h;
      GLenum format;
      int x, y;
      GLubyte *image = LoadRGBImage(DEMOS_DATA_DIR "tree3.rgb",
				    &w, &h, &format);

      if (!image) {
	 fprintf(stderr, "Error reading a texture.\n");
	 exit(-1);
      }

      for (y = 0; y < 128; y++)
	 for (x = 0; x < 128; x++) {
	    tex[x][y][0] = image[(y + x * 128) * 3];
	    tex[x][y][1] = image[(y + x * 128) * 3 + 1];
	    tex[x][y][2] = image[(y + x * 128) * 3 + 2];
	    if ((tex[x][y][0] == tex[x][y][1]) &&
		(tex[x][y][1] == tex[x][y][2]) && (tex[x][y][2] == 255))
	       tex[x][y][3] = 0;
	    else
	       tex[x][y][3] = 255;
	 }

      if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 128, 128, GL_RGBA,
				      GL_UNSIGNED_BYTE, (GLvoid *) (tex)))) {
	 fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr));
	 exit(-1);
      }
   }
   else {
      if (!LoadRGBMipmaps(DEMOS_DATA_DIR "tree2.rgba", GL_RGBA)) {
	 fprintf(stderr, "Error reading a texture.\n");
	 exit(-1);
      }
   }

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
		   GL_LINEAR_MIPMAP_LINEAR);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
Ejemplo n.º 19
0
void ButtonOverlayProcessor::renderOverlayImage() {

    regenerateOverlay_ = false;

    tgt::Texture* pickingTex = pickingPort_.getColorTexture();
    if(pickingTex->getPixelData())
        pickingTex->destroy();

    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);

    overlayPort_.activateTarget();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();

    glClearDepth(1.0);
    glDisable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    pickingPort_.activateTarget();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearDepth(1.0);
    glDisable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    TextureUnit overlayUnit;
    tgt::ivec2 groupCoords = inport_.getSize() - tgt::ivec2(horzBorder_.get(), vertBorder_.get());

    int count = 0;

    for(size_t i = 0; i < buttonProps_.size(); i++) {

        if(!isVisibleProps_.at(i)->get())
            continue;

        overlayPort_.activateTarget();
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

        // add support for transparent buttons in combination with user controlled transparency, otherwise
        // the texture transparency always has priority
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        overlayUnit.activate();
        if(buttonProps_.at(i)->get()) {
            //buttonTexturesPressed_.at(i)->bind();
            //buttonTexturesPressed_.at(i)->enable();
            buttonTexturePressed_->bind();
            buttonTexturePressed_->enable();
        } else {
            //buttonTexturesNonPressed_.at(i)->bind();
            //buttonTexturesNonPressed_.at(i)->enable();
            buttonTextureReleased_->bind();
            buttonTextureReleased_->enable();
        }
        LGL_ERROR;

        tgt::ivec2 radius = tgt::ivec2(buttonRadiusX_.get(), buttonRadiusY_.get());
        tgt::ivec2 centerCoords = groupCoords - tgt::ivec2(0, count*(groupBorder_.get() + 2*radius.y)) - radius;

        //radius.x = (float(buttonTexturePressed_->getWidth()) / float(buttonTexturePressed_->getHeight())) * radius.y;

        glColor4f(1.0f, 1.0f, 1.0f, opacity_.get());
        glBegin(GL_QUADS);

        tgt::vec2 ll = tgt::vec2(float(centerCoords.x - radius.x) / inport_.getSize().x, float(centerCoords.y - radius.y) / inport_.getSize().y);
        tgt::vec2 ur = tgt::vec2(float(centerCoords.x + radius.x) / inport_.getSize().x, float(centerCoords.y + radius.y) / inport_.getSize().y);
        ll = 2.0f * ll - 1.0f;
        ur = 2.0f * ur - 1.0f;

        glTexCoord2f(0.0f, 0.0f);
        glVertex2f(ll.x, ll.y);
        glTexCoord2f(1.0f, 0.0f);
        glVertex2f(ur.x, ll.y);
        glTexCoord2f(1.0f, 1.0f);
        glVertex2f(ur.x, ur.y);
        glTexCoord2f(0.0f, 1.0f);
        glVertex2f(ll.x, ur.y);

        glEnd();

        if(buttonProps_.at(i)->get())
            buttonTexturePressed_->disable();
        else
            buttonTextureReleased_->disable();

        renderFont(static_cast<int>(i), centerCoords);

        overlayPort_.deactivateTarget();
        glBlendFunc(GL_ONE, GL_ZERO);
        glDisable(GL_BLEND);

        pickingPort_.activateTarget();
        float col = float(i+1) / 255.f;
        glColor4f(col, col, col, 1.f);

        glRectf(ll.x, ll.y, ur.x, ur.y);
        pickingPort_.deactivateTarget();

        count++;
    }

    // download the picking texture to a buffer so we can perform picking on the cpu
    pickingPort_.getColorTexture()->downloadTexture();
    TextureUnit::setZeroUnit();
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
}
Ejemplo n.º 20
0
Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
                                 int width, int height)
{
    if (!tmpImage)
        return nullptr;

    BLOCK_START("OpenGLImageHelper::glLoad")
    // Flush current error flag.
    graphicsManager.getLastError();

    if (!width)
        width = tmpImage->w;
    if (!height)
        height = tmpImage->h;

    SDL_Surface *oldImage = tmpImage;
    tmpImage = convertSurfaceNormalize(tmpImage, width, height);
    if (!tmpImage)
        return nullptr;

    const int realWidth = tmpImage->w;
    const int realHeight = tmpImage->h;

    const GLuint texture = getNewTexture();
    bindTexture(texture);

    if (SDL_MUSTLOCK(tmpImage))
        SDL_LockSurface(tmpImage);

    if (mUseOpenGL != RENDER_MODERN_OPENGL &&
        mUseOpenGL != RENDER_GLES_OPENGL &&
        mUseOpenGL != RENDER_GLES2_OPENGL)
    {
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    }

    if (!mUseTextureSampler)
    {
        if (mBlur)
        {
            mglTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            mglTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        }
        else
        {
            mglTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            mglTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        }
    }
#if !defined(ANDROID) && !defined(__native_client__)
    mglTexParameteri(mTextureType, GL_TEXTURE_MAX_LEVEL, 0);
#endif  // !defined(ANDROID) && !defined(__native_client__)

    mglTexImage2D(mTextureType, 0, mInternalTextureType,
        tmpImage->w, tmpImage->h,
        0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);

#ifdef DEBUG_OPENGL
/*
    disabled for now, because debugger can't show it
    if (isGLNotNull(mglLabelObject))
    {
        const char *const text = "image text";
        mglLabelObject(GL_TEXTURE, texture, strlen(text), text);
    }
*/
#endif  // DEBUG_OPENGL

/*
    GLint compressed;
    glGetTexLevelParameteriv(mTextureType, 0,
        GL_TEXTURE_COMPRESSED_ARB, &compressed);
    if (compressed)
        logger->log("image compressed");
    else
        logger->log("image not compressed");
*/

#ifdef DEBUG_OPENGL_LEAKS
    textures_count ++;
#endif  // DEBUG_OPENGL_LEAKS

    if (SDL_MUSTLOCK(tmpImage))
        SDL_UnlockSurface(tmpImage);

    if (oldImage != tmpImage)
        MSDL_FreeSurface(tmpImage);

    GLenum error = graphicsManager.getLastError();
    if (error)
    {
        std::string errmsg = GraphicsManager::errorToString(error);
        reportAlways("Error: Image GL import failed: %s (%u)",
            errmsg.c_str(), error);
//        return nullptr;
    }

    BLOCK_END("OpenGLImageHelper::glLoad")
    return new Image(texture, width, height, realWidth, realHeight);
}
Ejemplo n.º 21
0
void renderScene(void) 
{
	update();

    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
	
	glViewport(0,0, field_width, field_height);

    // Draw quad to the screen in the corner
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);

    setupMatrices(0);

    int pass = number_of_passes;

    while (pass-- > 0)
    {
        // Swap source and destination
        src = 1-src;
        dest = 1-dest;

        // Draw to the source to update agent positions
        glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + src);
        drawBorder();
        drawAgents();

        // Draw mouse "agent"
        drawMouse();

        // Draw the shader to destination texture
        glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + dest);

        //glClear(GL_COLOR_BUFFER_BIT);

        //Using the field shader
        glUseProgramObjectARB(fieldShaderId);
        glUniform1iARB(fieldUniform, 7);
        glActiveTextureARB(GL_TEXTURE7);
        glBindTexture(GL_TEXTURE_2D, fieldTexIds[src]);

        drawFullScreenFieldQuad();

        glUseProgramObjectARB(0);
        glBindTexture(GL_TEXTURE_2D, 0);
    }

    setupMatrices(1);
	glViewport(0,0, window_width, window_height);

    // Draw quad to the screen
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    glClear( GL_COLOR_BUFFER_BIT);

    if (showField)
    {
        glActiveTextureARB(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, fieldTexIds[dest]);

        glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
        glEnable( GL_TEXTURE_2D );
        drawFullScreenWindowQuad();
        glDisable( GL_TEXTURE_2D );

        glBindTexture(GL_TEXTURE_2D, 0);
    }

    if (showField != 1) {
        float multx = window_width * 0.002;
        float multy = window_height * 0.002;
        glPointSize(5);
        int i;
        glColor3f(1,1,1);
        glBegin(GL_POINTS);
        for (i=0; i < maxAgents; i++)
        {
            if (agents[i].active) {
                glVertex2f(agents[i].pos[0] * multx + 2,
                           window_height - agents[i].pos[1] * multy - 2);
            }
        }
        glEnd();
        glPointSize(0.5);
    }

	glutSwapBuffers();

    if (vfgl_DrawCallback)
        vfgl_DrawCallback();
}
Ejemplo n.º 22
0
void ssgVtxTableSmoke::draw_geometry ()
{
	int num_colours = getNumColours();
	int num_normals = getNumNormals();
	float alpha;
	GLfloat modelView[16];
	sgVec3 A, B, C, D;
	sgVec3 right, up, offset;

	sgVec3 *vx = (sgVec3 *) vertices->get(0);
	sgVec3 *nm = (sgVec3 *) normals->get(0);
    sgVec4 *cl = (sgVec4 *) colours->get(0);
	alpha =  0.9f - ((float)(cur_life/max_life));
	glDepthMask(GL_FALSE);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	/*glPolygonOffset(-5.0f, +10.0f);*/
	/*glEnable(GL_POLYGON_OFFSET_FILL);*/

	// the principle is to have a right and up vector
	// to determine how the points of the quadri should be placed
	// orthogonaly to the view, parallel to the screen.

	/* get the matrix */
	// TODO: replace that, glGet stalls rendering pipeline (forces flush).
	glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

	// get the up and right vector from the matrice view

	offset[0] = offset[1] = offset[2] = 0.0f;

	int i;
	for (i = 0; i < 3; i++) {
		int j = i;
		int k;
		for (k = 0; k < 4; k++, j+=4) {
			if (k != 3) {
				offset[i] += modelView[j] * vx[0][k];
			} else {
				offset[i] += modelView[j];
			}
		}
	}
	//printf ("%f %f %f\n", offset[0], offset[1], offset[2]);

	tdble dist = sqrt(offset[0]*offset[0]
		+ offset[1]*offset[1]
		+ offset[2]*offset[2]);

	up[0] = modelView[1];
	up[1] = modelView[5];
	up[2] = modelView[9];

	right[0] = modelView[0];
	right[1] = modelView[4];
	right[2] = modelView[8];

	// compute the coordinates of the four points of the quadri.

	// up and right points
	C[0] = right[0]+up[0];
	C[1] = right[1]+up[1];
	C[2] = right[2]+up[2];

	// left and up
	D[0] = -right[0]+up[0];
	D[1] = -right[1]+up[1];
	D[2] = -right[2]+up[2];

	// down and left
	A[0] = -right[0]-up[0];
	A[1] = -right[1]-up[1];
	A[2] = -right[2]-up[2];

	// right and down
	B[0] = right[0]-up[0];
	B[1] = right[1]-up[1];
	B[2] = right[2]-up[2];

	glBegin ( gltype ) ;

	if (dist < 50.0f) {
		alpha *= (1.0f - exp(-0.1f * dist));
	}

	glColor4f(cur_col[0],cur_col[1],cur_col[2],alpha);
	if (num_colours == 1) {
		glColor4fv(cl[0]);
	}
	if (num_normals == 1) {
		glNormal3fv(nm[0]);
	}

	// the computed coordinates are translated from the smoke position with the x, y, z speed
	glTexCoord2f(0,0);
	glVertex3f(vx[0][0]+sizex*A[0],vx[0][1]+sizey*A[1], vx[0][2]+sizez*A[2]);
	glTexCoord2f(0,1);
	glVertex3f(vx[0][0]+sizex*B[0],vx[0][1]+sizey*B[1], vx[0][2]+sizez*B[2]);
	glTexCoord2f(1,0);
	glVertex3f(vx[0][0]+sizex*D[0],vx[0][1]+sizey*D[1], vx[0][2]+sizez*D[2]);
	glTexCoord2f(1,1);
	glVertex3f(vx[0][0]+sizex*C[0],vx[0][1]+sizey*C[1], vx[0][2]+sizez*C[2]);
	glEnd();

	glDisable(GL_POLYGON_OFFSET_FILL);
	glDepthMask(GL_TRUE);
	glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
}
Ejemplo n.º 23
0
void ofxFBOTexture::allocate(int w, int h, int internalGlDataType, int numSamples) {
	_isActive = false;
	
	// attempt to free the previous bound texture, if we can:
	clean();
	
	texData.width = w;
	texData.height = h;
	this->numSamples = numSamples;
	
#ifndef TARGET_OPENGLES	
    if (GLEE_ARB_texture_rectangle){
        texData.tex_w = w;
        texData.tex_h = h;
        texData.textureTarget = GL_TEXTURE_RECTANGLE_ARB;
    } else
#endif	
	{	
        texData.tex_w = ofNextPow2(w);
        texData.tex_h = ofNextPow2(h);
    }
	
#ifndef TARGET_OPENGLES	
	if (GLEE_ARB_texture_rectangle){
		texData.tex_t = w;
		texData.tex_u = h;
	} else
#endif	
	{
		texData.tex_t = w/texData.tex_w;
		texData.tex_u = h/texData.tex_h;
	}
	
	texData.width = w;
	texData.height = h;
	texData.bFlipTexture = true;
	texData.glTypeInternal = internalGlDataType;

#ifndef TARGET_OPENGLES	
	switch(texData.glTypeInternal) {
		case GL_RGBA32F_ARB:
		case GL_RGBA16F_ARB:
			texData.glType		= GL_RGBA;
			texData.pixelType	= GL_FLOAT;
			pixels				= new float[w * h * 4];
			break;
		default:
			texData.glType		= GL_LUMINANCE;
			texData.pixelType	= GL_UNSIGNED_BYTE;
			pixels				= new unsigned char[w * h * 4];
	}
#else
	texData.glType		= GL_RGBA;
	texData.pixelType	= GL_UNSIGNED_BYTE;
	pixels				= new unsigned char[w * h * 4];
#endif			
	
	
	// create & setup texture
	glGenTextures(1, (GLuint *)&texData.textureID);   // could be more then one, but for now, just one
	glBindTexture(texData.textureTarget, (GLuint)texData.textureID);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, texData.tex_w, texData.tex_h, 0, texData.glType, texData.pixelType, 0);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	
	
#ifndef TARGET_OPENGLES
	glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, (GLint *) &oldFramebuffer);
	
	if(numSamples ){
		// MULTISAMPLE //
		
		//THEO Create the render buffer for depth
		glGenRenderbuffersEXT(1, &depthBuffer);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
		glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, numSamples, GL_DEPTH_COMPONENT, texData.tex_w, texData.tex_h);
		
		//THEO multi sampled color buffer
		glGenRenderbuffersEXT(1, &colorBuffer);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorBuffer);
		glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, numSamples, texData.glTypeInternal, texData.tex_w, texData.tex_h);
		
		//THEO create fbo for multi sampled content and attach depth and color buffers to it
		glGenFramebuffersEXT(1, &mfbo);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mfbo);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorBuffer);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);

	}else{
		//THEO Create the render buffer for depth
		glGenRenderbuffersEXT(1, &depthBuffer);
		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texData.tex_w, texData.tex_h);
		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);
	}
	
	// create & setup FBO
	glGenFramebuffersEXT(1, &fbo);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
	
	// attach it to the FBO so we can render to it
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texData.textureTarget, (GLuint)texData.textureID, 0);
	
	GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		cout<<"glBufferTexture failed to initialize. Perhaps your graphics card doesnt support the framebuffer extension? If you are running osx prior to system 10.5, that could be the cause"<<endl;
		std::exit(1);
	}
	clear(0, 0, 0, 0);
	
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oldFramebuffer);
#else
	
	if(numSamples ){
		ofLog(OF_LOG_WARNING, "Multi-sampling not supported on OpenGL ES");
	}else{
	}
	
	
	glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *) &oldFramebuffer);

	// create & setup FBO
	glGenFramebuffersOES(1, &fbo);
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);
	
	// attach it to the FBO so we can render to it
	glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texData.textureTarget, (GLuint)texData.textureID, 0);
	
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFramebuffer);
	
#endif	

	
	texData.bAllocated = true;
}
Ejemplo n.º 24
0
//------------------------------------------------------------------------------
// drawFunc()
//------------------------------------------------------------------------------
void Display::drawFunc()
{
   Simulation::Player* own = getOwnship();

   const Basic::Pair* pair = nullptr;
   if (own != nullptr) pair = own->getSensorByType(typeid(RealBeamRadar));

   const RealBeamRadar* rdr = nullptr;
   if (pair != nullptr) rdr = static_cast<const RealBeamRadar*>( pair->object() );

   const GLubyte* image = nullptr;  // The image pixels
   if (rdr != nullptr) image = rdr->getImage();

   if (image != nullptr) {

      // Image width  (number of columns)
      GLsizei imgWidth = rdr->getImageWidth();

      // Image height (number of rows)
      GLsizei imgHeight = rdr->getImageHeight();

      GLint pixelSize = rdr->getPixelSize();
      GLenum format = GL_RGB;
      if (pixelSize == 4) format = GL_RGBA;

      if (testTexture) {
         // ---
         // Draw using texture map
         // ---

         glEnable(GL_TEXTURE_2D);
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

         if (texture == 0) {
            glGenTextures(1, &texture);
         }

         glBindTexture(GL_TEXTURE_2D, texture);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

//         double start = getComputerTime();

         glTexImage2D(GL_TEXTURE_2D, 0, pixelSize, imgWidth, imgHeight, 0, format, GL_UNSIGNED_BYTE, image);

         // B SCAN
         glBegin(GL_POLYGON);

            glTexCoord2f( 1.0f, 1.0f );
            glVertex2f(  1.0f,  1.0f );

            glTexCoord2f( 0.0f, 1.0f );
            glVertex2f( 0.0f, 1.0f );

            glTexCoord2f( 0.0f, 0.0f );
            glVertex2f(  0.0f, 0.0f );

            glTexCoord2f( 1.0f, 0.0f );
            glVertex2f( 1.0f, 0.0f );

         glEnd();

         glDisable(GL_TEXTURE_2D);
//         double end = getComputerTime();
//         double dtime = (end - start);
         //std::cout << "glTexImage2D() dtime = " << dtime << std::endl;
      }
      else {
         // ---
         // Draw using glDrawPixels()
         // ---

         glRasterPos2f(0.0, 0.0);

         //double start = getComputerTime();

         glDrawPixels(imgWidth, imgHeight, format, GL_UNSIGNED_BYTE, image);

         //double end = getComputerTime();
         //double dtime = (end - start);
         //std::cout << "glDrawPixels() dtime = " << dtime << std::endl;
      }
   }
}
Ejemplo n.º 25
0
//----------------------------------------------------------
void ofTexture::allocate(int w, int h, int internalGlDataType, bool bUseARBExtention){

	//our graphics card might not support arb so we have to see if it is supported.
	#ifndef TARGET_OPENGLES
		if (bUseARBExtention && GLEE_ARB_texture_rectangle){
			texData.tex_w = w;
			texData.tex_h = h;
			texData.tex_t = w;
			texData.tex_u = h;
			texData.textureTarget = GL_TEXTURE_RECTANGLE_ARB;
		} else 
	#endif
	{
		//otherwise we need to calculate the next power of 2 for the requested dimensions
		//ie (320x240) becomes (512x256)
		texData.tex_w = ofNextPow2(w);
		texData.tex_h = ofNextPow2(h);
		texData.tex_t = 1.0f;
		texData.tex_u = 1.0f;
		texData.textureTarget = GL_TEXTURE_2D;
	}

	texData.glTypeInternal = internalGlDataType;

	
	// MEMO: todo, add more types
	switch(texData.glTypeInternal) {
#ifndef TARGET_OPENGLES	
		case GL_RGBA32F_ARB:
			texData.glType		= GL_RGBA;
			texData.pixelType	= GL_FLOAT;
			break;
			
		case GL_RGB32F_ARB:
			texData.glType		= GL_RGB;
			texData.pixelType	= GL_FLOAT;
			break;

		case GL_LUMINANCE32F_ARB:
			texData.glType		= GL_LUMINANCE;
			texData.pixelType	= GL_FLOAT;
			break;
#endif			
			
		default:
			texData.glType		= GL_LUMINANCE;
			texData.pixelType	= GL_UNSIGNED_BYTE;
	}

	// attempt to free the previous bound texture, if we can:
	clear();

	glGenTextures(1, (GLuint *)&texData.textureID);   // could be more then one, but for now, just one

	glEnable(texData.textureTarget);

		glBindTexture(texData.textureTarget, (GLuint)texData.textureID);
	#ifndef TARGET_OPENGLES
		// can't do this on OpenGL ES: on full-blown OpenGL, 
		// internalGlDataType and glDataType (GL_LUMINANCE below)
		// can be different; on ES they must be exactly the same.
//		glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, (GLint)texData.tex_w, (GLint)texData.tex_h, 0, GL_LUMINANCE, PIXEL_TYPE, 0);  // init to black...
		glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, (GLint)texData.tex_w, (GLint)texData.tex_h, 0, texData.glType, texData.pixelType, 0);  // init to black...
	#else
		glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, texData.tex_w, texData.tex_h, 0, texData.glTypeInternal, GL_UNSIGNED_BYTE, 0);
	#endif

	
	glTexParameterf(texData.textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	glDisable(texData.textureTarget);

	texData.width = w;
	texData.height = h;
	#ifdef TARGET_OF_IPHONE
		texData.bFlipTexture = true; // textures need to be flipped for the iphone
	#else
		texData.bFlipTexture = false;
	#endif
	texData.bAllocated = true;
}
Ejemplo n.º 26
0
void SkyDome::draw(int time){
  
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, m_gradient);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

  float U = (float)time/(CYCLE);

  for(int i=0; i<m_nLat; i++){
    for(int j=0; j<m_nLong; j++){
      int a = i*(m_nLong+1) + j;
      int b = a + (m_nLong+1);


      float VTop = (float)(i+1)*2/(m_nLat+3);
      float VBot = (float)(i+2)*2/(m_nLat+3);

      glBegin(GL_TRIANGLES);
      glTexCoord2f(U,VTop);
      glVertex3d(m_vertices[a][0], m_vertices[a][1], m_vertices[a][2]);
      glTexCoord2f(U,VBot);
      glVertex3d(m_vertices[b][0], m_vertices[b][1], m_vertices[b][2]);
      glTexCoord2f(U,VTop);
      glVertex3d(m_vertices[a+1][0], m_vertices[a+1][1], m_vertices[a+1][2]);
      glEnd();

      glBegin(GL_TRIANGLES);
      glTexCoord2f(U,VBot);
      glVertex3d(m_vertices[b][0], m_vertices[b][1], m_vertices[b][2]);
      glVertex3d(m_vertices[b+1][0], m_vertices[b+1][1], m_vertices[b+1][2]);
      glTexCoord2f(U,VTop);
      glVertex3d(m_vertices[a+1][0], m_vertices[a+1][1], m_vertices[a+1][2]);
      glEnd();
    }
  }

  glDisable(GL_TEXTURE_2D);

  // calc sun position
  Point3D* sunPos = getSunPos(time);
  Point3D* moonPos = getMoonPos(time);

  //TODO calc sun color and size
  double sina = sin(getT(time, 0.1, 0.55)*M_PI);
  int sunSize = 2500 - sina*1200;
  Colour sunColor = Colour(1,0.85,0.7)*(1-sina) + Colour(1,1,1)*sina;


  // draw sun
  GLUquadricObj* qsphere = gluNewQuadric();

  gluQuadricDrawStyle(qsphere, GLU_FILL);
  gluQuadricOrientation(qsphere, GLU_OUTSIDE);
  gluQuadricTexture(qsphere, GL_FALSE);

  glColor3f(sunColor.R(),sunColor.G(),sunColor.B());
  glPushMatrix();
  glTranslatef((*sunPos)[0],(*sunPos)[1],(*sunPos)[2]);
  gluSphere(qsphere, sunSize, 20, 20);
  glPopMatrix();

  // draw moon
  GLUquadricObj* qsphere2 = gluNewQuadric();

  gluQuadricDrawStyle(qsphere2, GLU_FILL);
  gluQuadricOrientation(qsphere2, GLU_OUTSIDE);
  gluQuadricTexture(qsphere2, GL_FALSE);

  glColor3f(1,0.9,0.6);
  glPushMatrix();
  glTranslatef((*moonPos)[0],(*moonPos)[1],(*moonPos)[2]);
  gluSphere(qsphere2, 1000, 20, 20);
  glPopMatrix();

}
int
S9xOpenGLDisplayDriver::opengl_defaults (void)
{
    using_pbos = 0;
    if (config->use_pbos)
    {
        if (!load_pixel_buffer_functions ())
        {
            fprintf (stderr, _("pixel_buffer_object extension not supported.\n"));

            config->use_pbos = 0;
        }
        else
        {
            using_pbos = 1;
        }
    }

    using_shaders = 0;
    if (config->use_shaders)
    {
        if (!load_shaders (config->fragment_shader))
        {
            config->use_shaders = 0;
        }
        else
        {
            using_shaders = 1;
        }
    }

    tex_target = GL_TEXTURE_2D;
    texture_width = 1024;
    texture_height = 1024;
    dyn_resizing = FALSE;

    const char *extensions = (const char *) glGetString (GL_EXTENSIONS);

    if (extensions && config->npot_textures)
    {
        if (!using_shaders && strstr (extensions, "_texture_rectangle"))
        {
            tex_target = GL_TEXTURE_RECTANGLE;
            texture_width = scaled_max_width;
            texture_height = scaled_max_height;
            dyn_resizing = TRUE;
        }
        else if (strstr (extensions, "GL_ARB_texture_non_power_of_two"))
        {
            dyn_resizing = TRUE;
        }
    }

    glEnable (GL_VERTEX_ARRAY);
    glEnable (GL_TEXTURE_COORD_ARRAY);

    vertices[0] = 0.0f;
    vertices[1] = 0.0f;
    vertices[2] = 1.0f;
    vertices[3] = 0.0f;
    vertices[4] = 1.0f;
    vertices[5] = 1.0f;
    vertices[6] = 0.0f;
    vertices[7] = 1.0f;

    glVertexPointer (2, GL_FLOAT, 0, vertices);

    texcoords[0] = 0.0f;
    texcoords[5] = 0.0f;
    texcoords[6] = 0.0f;
    texcoords[7] = 0.0f;

    glTexCoordPointer (2, GL_FLOAT, 0, texcoords);

    if (config->use_pbos)
    {
        glGenBuffers (1, &pbo);
        glGenTextures (1, &texmap);

        glBindTexture (tex_target, texmap);
        glTexImage2D (tex_target,
                      0,
                      config->pbo_format == PBO_FMT_16 ? GL_RGB5_A1 : 4,
                      texture_width,
                      texture_height,
                      0,
                      PBO_GET_FORMAT (config->pbo_format),
                      PBO_GET_PACKING (config->pbo_format),
                      NULL);

        glBindBuffer (GL_PIXEL_UNPACK_BUFFER, pbo);
        glBufferData (GL_PIXEL_UNPACK_BUFFER,
                      texture_width * texture_height * 3,
                      NULL,
                      GL_STREAM_DRAW);

        glBindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
    }
    else
    {
        glGenTextures (1, &texmap);

        glBindTexture (tex_target, texmap);
        glTexImage2D (tex_target,
                      0,
                      GL_RGB5_A1,
                      texture_width,
                      texture_height,
                      0,
                      GL_BGRA,
                      GL_UNSIGNED_SHORT_1_5_5_5_REV,
                      NULL);
    }

    glEnable (GL_DITHER);

    glDisable (GL_POLYGON_SMOOTH);
    glShadeModel (GL_FLAT);
    glPolygonMode (GL_FRONT, GL_FILL);

    glEnable (GL_CULL_FACE);
    glCullFace (GL_BACK);

    glClearColor (0.0, 0.0, 0.0, 0.0);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    glDisable (GL_BLEND);
    glDisable (GL_DEPTH_TEST);
    glDisable (GL_TEXTURE_2D);
    glDisable (GL_TEXTURE_RECTANGLE);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glOrtho (0.0, 1.0, 0.0, 1.0, -1, 1);

    return 1;
}
Ejemplo n.º 28
0
void NsRendererOGL3::Draw(const NsQuad3D & quad)
{
	SetDrawColor(0.4f, 0.12f, 1.f);
	SetWorldMatrix(quad.GetWorldTransform());
		
	if(quad.bUseASCIIShader && !quad.shaderID < 1)
	{
		GLuint fontID = NsOGLResourceManager::Instance()->GetResourceID("/Textures/ASCII/ascii.png");
	
		glUseProgram(quad.shaderID);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture (GL_TEXTURE_2D, quad.textureID);
		GLint iTextureUniform = glGetUniformLocation(quad.shaderID, "colorMap");
		glUniform1i(iTextureUniform, 0);

		glActiveTexture(GL_TEXTURE1);
		glBindTexture (GL_TEXTURE_2D, fontID);
		GLint iASCIIUniform = glGetUniformLocation(quad.shaderID, "asciiMap");
		glUniform1i(iASCIIUniform, 1);
	
		glBegin (GL_QUADS);
		{
			glTexCoord2f (0.0, 0.0);
			glVertex3f (0.0, 0.0, 0.0);

			glTexCoord2f (1.0, 0.0);
			glVertex3f (quad.fWidth, 0.0, 0.0);

			glTexCoord2f (1.0, 1.0);
			glVertex3f (quad.fWidth, quad.fHeight, 0.0);

			glTexCoord2f (0.0, 1.0);
			glVertex3f (0.0, quad.fHeight, 0.0);
		}
		glEnd ();

		glUseProgram(0);
		glDisable(GL_TEXTURE_2D);

	}
	else
	{
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture (GL_TEXTURE_2D, quad.textureID);

		glBegin (GL_QUADS);
		{
			glTexCoord2f (0.0, 0.0);
			glVertex3f (0.0, 0.0, 0.0);

			glTexCoord2f (1.0, 0.0);
			glVertex3f (quad.fWidth, 0.0, 0.0);

			glTexCoord2f (1.0, 1.0);
			glVertex3f (quad.fWidth, quad.fHeight, 0.0);

			glTexCoord2f (0.0, 1.0);
			glVertex3f (0.0, quad.fHeight, 0.0);
		}
		glEnd ();
		glDisable(GL_TEXTURE_2D);
	}
}
Ejemplo n.º 29
0
/* virtual */
MStatus	hwUnlitShader::bind(const MDrawRequest& request,
							M3dView& view)
{
	MStatus status;

	// white, opaque.
	float bgColor[4] = {1,1,1,1};

	// Get path of current object in draw request
	currentObjectPath = request.multiPath();
	MString currentPathName( currentObjectPath.partialPathName() );

	updateTransparencyFlags(currentPathName);

	// Get decal texture name
	MString decalName = "";
	ShadingConnection colorConnection(thisMObject(), currentPathName, "color");

	// If the color attribute is ultimately connected to a file texture, find its filename.
	// otherwise use the default color texture.
	if (colorConnection.type() == ShadingConnection::TEXTURE &&
		colorConnection.texture().hasFn(MFn::kFileTexture))
	{
		// Get the filename of the texture.
		MFnDependencyNode textureNode(colorConnection.texture());
		MPlug filenamePlug( colorConnection.texture(), textureNode.attribute(MString("fileTextureName")) );
		filenamePlug.getValue(decalName);
		if (decalName == "")
			getFloat3(color, bgColor);
	}
	else
	{
		decalName = "";
		getFloat3(color, bgColor);
	}
	
	assert(glGetError() == GL_NO_ERROR);

	view.beginGL();

	glPushAttrib( GL_ALL_ATTRIB_BITS );
	glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);

	// Set the standard OpenGL blending mode.
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	// Change the constant alpha value. 
	float alpha = 1.0f - fConstantTransparency;

	// Set a color (with alpha). This color will be used directly if
	// the shader is not textured. Otherwise, the texture will get modulated
	// by the alpha.
	glColor4f(bgColor[0], bgColor[1], bgColor[2], alpha);


	// If the shader is textured...
	if (decalName.length() != 0)
	{
		// Enable 2D texturing.
		glEnable(GL_TEXTURE_2D);

		assert(glGetError() == GL_NO_ERROR);

		// Bind the 2D texture through the texture cache. The cache will keep
		// the texture around, so that it will only be loaded in video
		// memory once. In this example, the third parameter (mipmapping) is
		// false, so no mipmaps are generated. Note that mipmaps only work if
		// the texture has even dimensions.

		if(m_pTextureCache)
			m_pTextureCache->bind(colorConnection.texture(), MTexture::RGBA, false);	
		
		// Set minification and magnification filtering to linear interpolation.
		// For better quality, you could enable mipmapping while binding and
		// use GL_MIPMAP_LINEAR_MIPMAP in for minification filtering.
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	}

	// Disable lighting.
	glDisable(GL_LIGHTING);

	view.endGL();

	return MS::kSuccess;
}
Ejemplo n.º 30
0
    void Font::drawString(int x, int y, int fontWidth, int fontHeight, const char *str, DrawAnchor anchor) {
#ifndef GL_OES_draw_texture
#ifdef DEBUG
        printf("Unsupport GL_OES_draw_texture extension...\n");
#endif
#else
        glPushMatrix();

        glDisable(GL_DEPTH_TEST);
        glDisable(GL_FOG);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA

        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, m_texture->textureId);

        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        glColor4f(m_color->red, m_color->green, m_color->blue, m_color->alpha);

        GLuint len = strlen(str);
        for (GLuint i = 0; i < len; i++) {
            int index = (int)(str[i] - 32);
#if (defined(DEBUG) && defined(SHOW_FONT_POS))
            printf("str[%d]: %c, index: %d\n", i, str[i], index);
#endif
            GLint crop[4] = { 0, 0, m_charWidth, m_charHeight };

            int x_idx = index % m_colCount;
            int y_idx = (int)(index / m_colCount);
            crop[0] = x_idx * m_charWidth;
            crop[1] = (m_rowCount - y_idx) * m_charHeight;
#if (defined(DEBUG) && defined(SHOW_FONT_POS))
            printf("x_idx: %d, y_idx: %d, crop[0]: %d, crop[1]: %d\n", x_idx, y_idx, crop[0], crop[1]);
#endif

            glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);

            //calc the x, y & draw
            int scr_width = World::getInstance()->getWidth();
            int scr_height = World::getInstance()->getHeight();

            switch (anchor) {
            case(TOP_LEFT):
                //if draw from top & left, set y with screen height - image draw height
                glDrawTexiOES(x + i * fontWidth, scr_height - fontHeight - y, 0, fontWidth, fontHeight);
                break;
            case(TOP_RIGHT):
                glDrawTexiOES(scr_width - (len - i) * fontWidth - x, scr_height - fontHeight - y, 0, fontWidth, fontHeight);
                break;
            case(BOTTOM_RIGHT):
                glDrawTexiOES(scr_width - (len - i) * fontWidth - x, y, 0, fontWidth, fontHeight);
                break;
            case(BOTTOM_LEFT):
            default:
                glDrawTexiOES(x + i * fontWidth, y, 0, fontWidth, fontHeight);
                break;
            }

//            glDrawTexiOES(x + i * fontWidth, y, 0, fontWidth, fontHeight);
        }

        glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        glDisable(GL_TEXTURE_2D);

		glPopMatrix();
#endif
    }