Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualtanzanite7

Posted 20 April 2013 - 04:26 PM

Render my rasterizer

  glBegin(GL_POINTS);
  glPushMatrix();
  int const RenderBufferSize = m_bufferWidth * m_bufferHeight;
  for (int i = 0; i < RenderBufferSize; ++i)
  {
    int x = i % m_bufferWidth;
    int y = i / m_bufferWidth;
    int halfWidth = m_bufferWidth / 2;
    int halfHeight = m_bufferHeight / 2;

    glColor4ubv(m_renderBuffer[i]);
    glVertex2i(x - halfWidth, halfHeight - y);
  }
  glPopMatrix();
  glEnd();


Erm... this is silly. Just upload your buffer as texture and render it as one quad.

As for the problem: your vertex coordinates are wrong ... of course. Last i used something as ancient was at least over half a decade ago ... i do not remember the intrinsics of the deprecated glOrtho stuff. So, can not give a fixed version of your code (i sure as hell do not want to remember that old crap). However, the core of the issue is bound to be bad coordinates:
* bottom left of normalized device coordinates (ie. after modelview/projection transformation and perspective divide) addresses the bottom left of the pixel at bottom left.
* pixels have size (ie. bottom left pixel is between (0,0) and (1,1)) ... your integer coordinates tell to draw at the exact middle of adjecent pixels.
=> add floating point errors and stuff will expectedly be drawn at "random" to whichever pixel it sees being the closest.

PS. if you are learning OpenGL then please consider throwing the ancient book away and follow something newer (recommending "OGL3.3 core" as the starting point - ignore all the deprecated cruft).

edit: also, your viewport and glOrtho are probably mismatching (by 1 pixel).

#2tanzanite7

Posted 20 April 2013 - 04:26 PM

Render my rasterizer

  glBegin(GL_POINTS);
  glPushMatrix();
  int const RenderBufferSize = m_bufferWidth * m_bufferHeight;
  for (int i = 0; i < RenderBufferSize; ++i)
  {
    int x = i % m_bufferWidth;
    int y = i / m_bufferWidth;
    int halfWidth = m_bufferWidth / 2;
    int halfHeight = m_bufferHeight / 2;

    glColor4ubv(m_renderBuffer[i]);
    glVertex2i(x - halfWidth, halfHeight - y);
  }
  glPopMatrix();
  glEnd();


Erm... this is silly. Just upload your buffer as texture and render it as one quad.

As for the problem: your vertex coordinates are wrong ... of course. Last i used something as ancient was at least over half a decade ago ... i do not remember the intrinsics of the deprecated glOrtho stuff. So, can not give a fixed version of your code (i sure as hell do not want to remember that old crap). However, the core of the issue is bound to be bad coordinates:
* bottom left of normalized device coordinates (ie. after modelview/projection transformation and perspective divide) addresses the bottom left of the pixel at bottom left.
* pixels have size (ie. bottom left pixel is between (0,0) and (1,1)) ... your integer coordinates tell to draw at the exact middle of adjecent pixels.
=> add floating point errors and stuff will expectedly be drawn at "random" to whichever pixel it sees being the closest.

PS. if you are learning OpenGL then please consider throwing the ancient book away and follow something newer (recommending "OGL3.3 core" as the starting point - ignore all the deprecated cruft).

edit: also, your viewport and glOrtho are probably mismatching also (by 1 pixel).

#1tanzanite7

Posted 20 April 2013 - 04:16 PM

Render my rasterizer

  glBegin(GL_POINTS);
  glPushMatrix();
  int const RenderBufferSize = m_bufferWidth * m_bufferHeight;
  for (int i = 0; i < RenderBufferSize; ++i)
  {
    int x = i % m_bufferWidth;
    int y = i / m_bufferWidth;
    int halfWidth = m_bufferWidth / 2;
    int halfHeight = m_bufferHeight / 2;

    glColor4ubv(m_renderBuffer[i]);
    glVertex2i(x - halfWidth, halfHeight - y);
  }
  glPopMatrix();
  glEnd();


Erm... this is silly. Just upload your buffer as texture and render it as one quad.

As for the problem: your vertex coordinates are wrong ... of course. Last i used something as ancient was at least over half a decade ago ... i do not remember the intrinsics of the deprecated glOrtho stuff. So, can not give a fixed version of your code (i sure as hell do not want to remember that old crap). However, the core of the issue is bound to be bad coordinates:
* bottom left of normalized device coordinates (ie. after modelview/projection transformation and perspective divide) addresses the bottom left of the pixel at bottom left.
* pixels have size (ie. bottom left pixel is between (0,0) and (1,1)) ... your integer coordinates tell to draw at the exact middle of adjecent pixels.
=> add floating point errors and stuff will expectedly be drawn at "random" to whichever pixel it sees being the closest.

PS. if you are learning OpenGL then please consider throwing the ancient book away and follow something newer (recommending "OGL3.3 core" as the starting point - ignore all the deprecated cruft).

PARTNERS