It is currently Fri Sep 22, 2017 5:22 pm

All times are UTC - 5 hours




 Page 1 of 1 [ 5 posts ] 
Author Message
 Post subject: Shader VMK 18 - Render OpenGL v1.0
PostPosted: Sat Oct 20, 2012 6:14 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
In this video I introduce how to render things onto the screen using v1.0 of the OpenGL API. This is how things were done in the game engine/ghost toast series for the most part.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 18 - Render OpenGL v1.0
PostPosted: Sat Oct 18, 2014 2:45 am 

Joined: Thu Sep 27, 2007 5:51 pm
Posts: 48
Hey!
For some reason my hexagon won't rotate.
From Engine.cpp
float Engine::getTimeDifference() {
   LARGE_INTEGER currentTime;
   QueryPerformanceCounter(&currentTime);

   float fDeltaTimeSeconds = static_cast<float>((currentTime.QuadPart - m_previousTime.QuadPart) * m_dTimeScaleFactor);
   m_previousTime = currentTime;

   return glm::clamp(fDeltaTimeSeconds, 0.0f, 0.25f);
}

void Engine::processFrame() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

   render(getTimeDifference());

   if (!SwapBuffers(m_hDc)) {
      throw ExceptionHandler("SwapBuffers failed");
   }
}


From Game.cpp
void Game::render(float fTimeDifferenceInSeconds) {
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glTranslatef(0, 0, -1.5);

   const float fSpeedDegreesPerSecond = 25.0f;
   static float fRotationAngleDegrees = 0;
   fRotationAngleDegrees += fSpeedDegreesPerSecond * fTimeDifferenceInSeconds;
   if (fRotationAngleDegrees > 360.0f) {
      fRotationAngleDegrees -= 360.0f;
   }
   glRotatef(fRotationAngleDegrees, 0, 0, 1.0f);

   glBegin(GL_TRIANGLES);
.
.
.


The hexagon is there, it's just not rotating. I can't see any difference between Marek's and my rotation code, could it be something
I missed from earlier? I logged the fRotationAngleDegrees to the console just before the glRotatef, and the float was steadily increasing.

This is how the timer is setup in the Engine constructor:
   // Setup timer.
   LARGE_INTEGER frequency;
   if (!QueryPerformanceCounter(&frequency)) {
      throw ExceptionHandler("Hardware does not support high-resolution performance counter");
   }
   m_dTimeScaleFactor = 1.0 / frequency.QuadPart;

   // Get initial time.
   QueryPerformanceCounter(&m_previousTime);


Thanks!


Offline
 Profile  
 
 Post subject: Re: Shader VMK 18 - Render OpenGL v1.0
PostPosted: Sat Oct 18, 2014 4:02 pm 

Joined: Mon Mar 24, 2014 2:25 pm
Posts: 69
Hey Gory,

It's been awhile since working with the earlier versions of OpenGL, but looking at your code it looks like while the rotation vector is being calculated you are not using the result to recalculate your view matrix.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 18 - Render OpenGL v1.0
PostPosted: Sun Oct 19, 2014 7:00 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
GoryImpaler wrote:
I logged the fRotationAngleDegrees to the console just before the glRotatef, and the float was steadily increasing.


What are the values that you are seeing for fRotationAngleDregrees?

Also what does your whole render function look. Need to see what you wrote between the glBegin and glEnd calls.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 18 - Render OpenGL v1.0
PostPosted: Mon Oct 20, 2014 9:45 am 

Joined: Thu Sep 27, 2007 5:51 pm
Posts: 48
Marek wrote:
GoryImpaler wrote:
I logged the fRotationAngleDegrees to the console just before the glRotatef, and the float was steadily increasing.


What are the values that you are seeing for fRotationAngleDregrees?

Also what does your whole render function look. Need to see what you wrote between the glBegin and glEnd calls.


I'm past that so it's using VBOs. It actually does rotate, just veeeeeeeeeery slowly. If I set fSpeedDegreesPerSecond = 3000.0f, then the
fRotationAngleDegrees increase by 1 about every second.

void Game::render(float fTimeDifferenceInSeconds) {
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glTranslatef(0, 0, -1.5f);

   const float fSpeedDegreesPerSecond = 3000.0f;
   static float fRotationAngleDegrees = 0;
   fRotationAngleDegrees += fSpeedDegreesPerSecond * fTimeDifferenceInSeconds;
   if (fRotationAngleDegrees > 360.0f) {
      fRotationAngleDegrees -= 360.0f;
   }
   glRotatef(fRotationAngleDegrees, 0, 0, 1.0f);
   std::ostringstream strRotation;
   strRotation << fRotationAngleDegrees;
   Logger::log(Logger::TYPE_INFO, strRotation);

   glBindBuffer(GL_ARRAY_BUFFER, m_vboColor);
   glColorPointer(4, GL_FLOAT, 0, nullptr);

   glBindBuffer(GL_ARRAY_BUFFER, m_vboPosition);
   glVertexPointer(3, GL_FLOAT, 0, nullptr);

   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vboIndices);

   glEnableClientState(GL_COLOR_ARRAY);
   glEnableClientState(GL_VERTEX_ARRAY);

   glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, nullptr);

   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_COLOR_ARRAY);

   glBindBuffer(GL_ARRAY_BUFFER, 0);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

}


float Engine::getTimeDifference() {
   LARGE_INTEGER currentTime;
   QueryPerformanceCounter(&currentTime);

   float fDeltaTimeSeconds = static_cast<float>((currentTime.QuadPart - m_previousTime.QuadPart) * m_dTimeScaleFactor);
   m_previousTime = currentTime;

   return glm::clamp(fDeltaTimeSeconds, 0.0f, 0.25f);
}


Edit: Say whaaaat? This guy did something incredibly stupid again, like using QueryPerformanceCounter instead of QueryPerformanceFrequency?
Yeah... I did. Problem solved.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron