Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lesson 6 problem (mirrored textures)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 001i   Members   -  Reputation: 100

Like
0Likes
Like

Posted 08 May 2010 - 09:44 AM

Hi, I'm trying to modify Lesson 6 to make it use the Corona library for the image loading part. The problem here is that currently it looks like this... which is obviously not okay, but I have no idea what causes it. Is it me doing something wrong, or is it because Corona "sorts" the image differently in memory, or maybe something else entirely? Here's the code for the loader and the draw function (the latter is mostly a pure C&P though, but I'll post it here anyway just in case):
BOOL GLDrawObject::LoadTexture(char* pFilename, int iTexNo)
{    
	if (iTexNo>(TEX_Q-1))
		{ MessageBox (HWND_DESKTOP, "Texture index out of range", "FAIL", MB_OK | MB_ICONEXCLAMATION);
		  return FALSE; }

    corona::Image* Image = corona::OpenImage(pFilename, corona::FF_AUTODETECT);

    if (!Image)
		{ MessageBox (HWND_DESKTOP, "Error loading texture", "FAIL", MB_OK | MB_ICONEXCLAMATION);
		  return FALSE; }

	m_stTexArray[iTexNo].iWidth		= Image->getWidth();
	m_stTexArray[iTexNo].iHeight	= Image->getHeight();
	m_stTexArray[iTexNo].sImageData = (GLubyte*)Image->getPixels();

	glGenTextures(1, &m_stTexArray[iTexNo].iTexID);

	glBindTexture(GL_TEXTURE_2D, m_stTexArray[iTexNo].iTexID);

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

	glTexImage2D(GL_TEXTURE_2D, 0, 3, m_stTexArray[iTexNo].iWidth, m_stTexArray[iTexNo].iHeight,
				 0, GL_RGB, GL_UNSIGNED_BYTE, m_stTexArray[iTexNo].sImageData);

    delete Image;
    
	return TRUE;
}

void GLDrawObject::Draw(void)
{	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Screen And The Depth Buffer
	glLoadIdentity();										// Reset The View
	glTranslatef(0.0f,0.0f,-5.0f);							// Move Into The Screen 5 Units

	glRotatef(m_fXrot,1.0f,0.0f,0.0f);						// Rotate On The X Axis
	glRotatef(m_fYrot,0.0f,1.0f,0.0f);						// Rotate On The Y Axis
	glRotatef(m_fZrot,0.0f,0.0f,1.0f);						// Rotate On The Z Axis

	glBindTexture(GL_TEXTURE_2D, m_stTexArray[m_iTexNo].iTexID);				// Select Our Texture

	glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
	glEnd();
}

[Edited by - 001i on May 8, 2010 5:32:18 PM]

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS