Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Rendering two textures with different dimensions ?

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    3

    Rendering two textures with different dimensions ?

    I have two textures that I want to render in Glut, one is 71x96 and the other one is 75x105 pixels.
    I'm having troubles rendering the second texture, which renders 71x96 instead of 75x105.

    Here is my code...

    First, I have a drawengine class to do the rendering:

    Code :
    drawengine::drawengine(float w, float h)
    {
    	float xratio = 2 / w;
    	float yratio = 2 / h;
     
    	width = 1.0f;
    	height = 1.0f;
     
    	texture_w[0] = 71 * xratio;
    	texture_h[0] = 96 * yratio;
     
    	texture_w[1] = 75 * xratio;
    	texture_h[1] = 105 * yratio;
     
    	// create textures.
    	createtexture();
    }

    and createtexture() function to take care of loading the textures using SOIL library.

    Code :
    void drawengine::createtexture()
    {
    	int index;
    	char* filename[2] = {"texture1.png", "texture2.png"};
     
    	for(index = 0; index < 2; index++)
    	{
    		// load an image file directly as a new OpenGL texture
    		textures[index] = SOIL_load_OGL_texture
    		(
    			filename[index],
    			SOIL_LOAD_AUTO,
    			SOIL_CREATE_NEW_ID,
    			SOIL_FLAG_MIPMAPS /*| SOIL_FLAG_INVERT_Y*/ | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    		);
     
    		// check for an error during the load process
    		if(textures[index] == 0)
    			std::cout << "file not found";
     
    		// Typical Texture Generation Using Data From The Bitmap
    		glBindTexture(GL_TEXTURE_2D, textures[index]);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    	}
    }


    Second, drawtexture():

    Code :
    bool drawengine::drawtexture(int index, float x, float y)
    {
    	if((-width <= x && x <= width) && (-height <= y && y <= height))
    	{
    		// draw texture
    		glEnable(GL_BLEND);
    		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    		glEnable(GL_TEXTURE_2D);
    		glBindTexture(GL_TEXTURE_2D, textures[index]);
     
    		glLoadIdentity();
    		glTranslatef(x, y, 0.0f);
    		glBegin(GL_QUADS);
    			glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f , 0.0f, 0.0f);
    			glTexCoord2f(1.0f, 0.0f); glVertex3f(texture_w[index], 0.0f, 0.0f);
    			glTexCoord2f(1.0f, 1.0f); glVertex3f(texture_w[index],-texture_h[index], 0.0f);
    			glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f,-texture_h[index], 0.0f);
    		glEnd();
     
    		glDisable(GL_TEXTURE_2D);
    		glDisable(GL_BLEND);
     
    		return true;
    	}
    	else
    		return false;
    }


    Then, render(), the function I pass to glutDisplayFunc() and glutIdleFunc(). de is a pointer of type drawengine.

    Code :
    void render()
    {
    	// OpenGL...
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glClearColor(0.1f, 0.9f, 0.3f, 0.0f);
     
    	de->drawtexture(/*texture1*/ 0, -0.9f, 0.8f);  // draws a 71x96 quad. ok.
    	de->drawtexture(/*texture2*/ 1, -0.9f, 0.8f);  // draws a 71x96 quad. ????!!
     
    	// swaps the buffers of the current window if double buffered. 
    	glutSwapBuffers();
    }

    Thanks in advance.
    Last edited by _Shepherd; 11-02-2012 at 01:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •