Jump to content
  • Advertisement
Sign in to follow this  
AnthonyVelazquez

OpenGL Displaying a 2D Image

This topic is 1993 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok so I have a OpenGL application that displays a AVI, so far I have that working. Now I am trying to have it display a 2D Image. My program inceases "phase" everytime I press the enter key and when it is at phase 1, it should display a 2D image but it isnt working, 

 

This is my update function:

void Update (DWORD milliseconds)								// Perform Motion Updates Here
{
	if (g_keys->keyDown [VK_ESCAPE] == TRUE)					// Is ESC Being Pressed?
	{
		TerminateApplication (g_window);						// Terminate The Program
	}

	if (g_keys->keyDown [VK_F1] == TRUE)						// Is F1 Being Pressed?
	{
		//ToggleFullscreen (g_window);							// Toggle Fullscreen Mode
		OpenAudio();
	}
	if(g_keys->keyDown [VK_RETURN] == TRUE)
	{
		phase++;
	}
	next+=milliseconds;											// Increase next Based On The Timer
	frame=next/mpf;												// Calculate The Current Frame

	if (frame>=lastframe)										// Are We At Or Past The Last Frame?
	{
		frame=0;												// Reset The Frame Back To Zero (Start Of Video)
		next=0;													// Reset The Animation Timer (next)
	}
}

 

This is my actual drawing

 

void Draw (void)												// Draw Our Scene
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer
	switch(phase)
	{
	case 0:
	GrabAVIFrame(frame);										// Grab A Frame From The AVI

	if (bg)														// Is Background Visible?
	{
		glLoadIdentity();										// Reset The Modelview Matrix
		glBegin(GL_QUADS);										// Begin Drawing The Background (One Quad)
			// Front Face
			glTexCoord2f(1.0f, 1.0f); glVertex3f( 15.3f,  8.3f, -20.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-15.3f,  8.3f, -20.0f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-15.3f, -8.3f, -20.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 15.3f, -8.3f, -20.0f);
		glEnd();												// Done Drawing The Background
	}
	break;
	case 1:

	glBindTexture( GL_TEXTURE_2D, texture );

      glBegin( GL_QUADS );
      glTexCoord2f(1.0f, 1.0f); glVertex3f( 15.3f,  8.3f, -20.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-15.3f,  8.3f, -20.0f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-15.3f, -8.3f, -20.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 15.3f, -8.3f, -20.0f);
      glEnd();
	break;
	}

	
	glFlush ();													// Flush The GL Rendering Pipeline
}

 

Any help would be appreciated

Share this post


Link to post
Share on other sites
Advertisement

Judging by the names of your code, phase is increased beyond 1 quite rapidly, since the name of that array suggests it is increased every frame as long as the key is held.

Only increase it when the key is pressed, not held.

 

Additionally, don’t call glFlush() ever unless you have a very specific reason to do so.

Also additionally too as well, don’t bother even learning immediate mode (glBegin()/glEnd()).  It should never have even existed in the first place and you are only wasting time your time by learning/using it, since you will end up learning/using VBO’s either way.  Why not skip to the end?

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!