Results 1 to 2 of 2

Thread: Drawing & aligning textures & view

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    6

    Drawing & aligning textures & view

    I need help .

    I'm trying to draw multiple textures, align them together & draw a decent view. The textures themselves are like rectangle prism (ie 3D like);
    http://i.imgur.com/y3mM2r8.jpg
    With different fixed widths, but with variable heights. The edges of the prism need to align to others along pink left & pink bottom/right face.

    *Following is extract of what I'm currently using following;

    Code :
    	glClearColor(1, 1, 1, 1);
    	glDisable(GL_DEPTH_TEST);
    	glDepthMask(GL_TRUE);
    	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    	glEnable(GL_TEXTURE_2D);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    LoadTextures()
    {
    		glBindTexture(GL_TEXTURE_2D, pGLUINT[iItem]);
    		glTexImage2D(GL_TEXTURE_2D, 0, 4, Imgwidth, Imgheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, Imgrgba);
    		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    		glEnable(GL_TEXTURE_2D);
    }
     
    void DrawScene()
    {
    	CRect rWnd;
    	GetClientRect(&rWnd);
    	glViewport(0,0,rWnd.Width(),rWnd.Height());
     
    	glMatrixMode(GL_PROJECTION);		
    	glLoadIdentity();					      
     
    	glOrtho(-20, 80, -20, 60, -1, 1);
     
    	glMatrixMode(GL_MODELVIEW); 
    	glLoadIdentity();
     
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();						
     
    	glTranslatef(-14.50, 14.5f, 0.0f);
     
    	DrawPrisms();
    }
     
    void DrawPrisms()
    {
    	std::list<Textures>::iterator itText = m_Textures.begin();
    	for (; itText != m_Textures.end(); ++itText)
    	{
    		//subsequent textures need to align with previous one.
     
    		glPushMatrix();
     
    		const float Prism = itText->mSize;
     
    		float fL = itText->LocX;
    		float fR = fL + Prism;
     
    		float fB = itText->LocY;
    		float fT = fB + Prism;
     
    		fT = fT * -1;
    		fB = fB * -1;
     
    		glBindTexture(GL_TEXTURE_2D, itText->mNum);
    		glEnable(GL_BLEND);
    		glBegin(GL_QUADS);
     
    		glTexCoord2f(0, 0);//TL
    		glVertex3f(fL, fT, 0);
    		glTexCoord2f(0, 1);//BL
    		glVertex3f(fL, fB, 0);
    		glTexCoord2f(1, 1);//BR
    		glVertex3f(fR, fB, 0);
    		glTexCoord2f(1, 0);//TR
    		glVertex3f(fR, fT, 0);
    		glEnd();
     
    		glPopMatrix();
    	}
    }


    Main problems I'm having;
    -aligning textures together properly.
    -texture overlapping.


    Would appreciate any help .
    Thank you.

    ps I understand this is depreciated code.

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    6
    Well managed to mostly sort my problem;

    -aligning textures together properly.
    It's not perfect, but I've had to do something along lines of;

    Code :
    				pImage->fLeft = (((pImage->TileX) * fImgWidth) - fAdjustX)) - (((pImage->TileY * fImgWidth) - pImage->TileY*fAdjustX));
    				pImage->fTop = (((pImage->TileY) * fImgHeight) - fAdjustY)) + (((pImage->TileX*fImgHeight) - pImage->TileX*fAdjustY));


    -texture overlapping.
    Sorted mostly by utilising z order as follows;

    Code :
    		glTexCoord2f(0, 0);//TL
    		glVertex3f(fL, fT, -0.75);
    		glTexCoord2f(0, 1);//BL
    		glVertex3f(fL, fB, 1.00);
    		glTexCoord2f(1, 1);//BR
    		glVertex3f(fR, fB, 0.75);
    		glTexCoord2f(1, 0);//TR
    		glVertex3f(fR, fT, -1.00);

Similar Threads

  1. Problem Aligning Textures
    By cpsmusic in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-20-2006, 12:52 PM
  2. Drawing the view frustum
    By Aeluned in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-28-2005, 06:01 AM
  3. aligning vectors?
    By Jeeeez in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-19-2002, 08:00 AM
  4. Aligning a frustum view with an ortho view
    By Siwko in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 05-22-2001, 04:52 AM
  5. Aligning the world...
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-15-2000, 08:03 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
  •  
Proudly hosted by Digital Ocean