Advertisement

sprite sheet

Started by September 03, 2018 11:54 PM
41 comments, last by Rutin 6 years, 2 months ago

well jtippets I finally solved my problem here is the code I am using


void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);

	glGenTextures(8, &texture[1]);
	glBindTexture(GL_TEXTURE_2D,texture[0]);

	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f, 0.0f,0.0f); 
	
	glVertex3f(-1.0f, -1.0f, 0.0f);
	glTexCoord3f(0.125f, 0.0f,0.0f); 
	
	glVertex3f(-1.0f, 1.0f, 0.0f);
	glTexCoord3f(0.125f, 1.0f,0.0f); 
	
	glVertex3f(1.0f, 1.0f, 0.0f);
	glTexCoord3f(0.0f, 1.0f,0.0f); 
	
	glVertex3f(1.0f, -1.0f, 0.0f);
	glEnd();

	glutSwapBuffers();
}

 

I am able to rotate a sprite using the arrow keys, hooray I actually solved my problem. I have a small problem, my code renders the lines between sprites. here is my code so far.


void handleSpecialKeypress(int key, int x, int y)
{
	switch (key)
	{
	case GLUT_KEY_LEFT:
		rotate -= 0.125f;
		if (rotate <= 0.125f)
		{
			rotate = 0.875f;
		}
		break;
	case GLUT_KEY_RIGHT:
		rotate += 0.125f;
		if (rotate >= 1.0f)
		{
			rotate = 0.0f;
		}
		break;
	}
	glutPostRedisplay();
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);

	glGenTextures(8, &texture[1]);
	glBindTexture(GL_TEXTURE_2D,texture[0]);

	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f+rotate, 0.0f,0.0f); 
	
	glVertex3f(-0.5f, -0.5f, 0.0f);
	glTexCoord3f(0.125f+rotate, 0.0f,0.0f); 
	
	glVertex3f(-0.5f, 0.5f, 0.0f);
	glTexCoord3f(0.125f+rotate, 1.0f,0.0f); 
	
	glVertex3f(0.5f, 0.5f, 0.0f);
	glTexCoord3f(0.0f+rotate, 1.0f,0.0f); 
	
	glVertex3f(0.5f, -0.5f, 0.0f);
	glEnd();

	glutSwapBuffers();
}

 

Advertisement

I have a small problem in that my code renders the sprite with the lines between sprites

Im guessing you made your sprite sheet with actual lines between the frames, which are being picked up by texture filtering. Solution: erase those lines. They serve no practical purpose. Also, check your filter settings. If you are drawing your sprites without scaling, and if there is the possibility of bleeding from adjacent frames even with the lines erased, nearest filtering is the way to go.

what do you mean by filtering, and should I erase using paint?

26 minutes ago, phil67rpg said:

what do you mean by filtering, and should I erase using paint?

... erase with whatever you want? Google texture filtering

Advertisement

Filtering refers to code in your LoadGLTextures function. You set the texture parameters toward the end with your two glTexParameteri calls. Refer to this official wiki document for details.

 

 

musician pretending to be a programmer, pretending to be an artist.

2 hours ago, phil67rpg said:

what do you mean by filtering, and should I erase using paint?

Show us your actual sprite sheet and we can tell you if it's due to your code or actual image file.... Make sure it's the same one you're loading when the issue appears.

Programmer and 3D Artist

well I erased the lines using paint, all appears to be working, what should I do next in making my game?

Please do not use these question threads as progress updates, or to ask general, wide-ranging subjective advice about design. Once a question has been answered, if you have further questions unrelated to the original question, start a new thread. Confine progress updates to a blog; you have been warned about that before.

This topic is closed to new replies.

Advertisement