• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
telaryus

Odd issue when rendering

7 posts in this topic

Alright... short story is that stuff like this always happens when I try and do graphics. One thinks I would learn, but apparently I'm a masochist. So...

 

Nothing really fancy, small project that sets up a window to draw to.

 

What I am trying to achieve, for personal reasons, is to write my own rasterizer.

 

So first things first here are some links to the issue that I am encountering:

https://www.dropbox.com/s/fmuk9rycvnnyqqg/HATE.png

https://www.dropbox.com/s/dyqibeo31qc448y/HATE%202.png

https://www.dropbox.com/s/979twrhf1g8dkcx/HATE%203.png

 

And here is the code:

Creating the view:

wglMakeCurrent(hdc, hglrc);

glClearColor(0.5f, 0.1f, 0.15f, 1.0f);
glClearDepth(1.0f);
glShadeModel(GL_FLAT);

int width = 0;
int height = 0;
_renderTarget->GetSize(&width, &height);

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-width/2, width/2, -height/2, height/2, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

 

 

 

Render the fixed function test background

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
  glRotatef(_spin, 0.0f, 0.0, 1.0f);
  glColor3f(0.3f, 0.1f, 0.15f);
  glRectf(-150.0f, -150.0f, 150.0f, 150.0f);
  glPopMatrix();

  _rasterizer->Render();

  HDC hdc = GetDC(_renderTarget->GetHandle());
  SwapBuffers(hdc);
  ReleaseDC(_renderTarget->GetHandle(), hdc);

 

 

 

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();

 

Hopefully that is enough info, if not just ask.

 

Any help is greatly appreciated.

0

Share this post


Link to post
Share on other sites

So what is the issue?

In:

int x = i % m_bufferWidth;
int y = i / m_bufferWidth;
int halfWidth = m_bufferWidth / 2;
int halfHeight = m_bufferHeight / 2;

 

Shouldn't it be:

int y = i / m_bufferHeight;

 

 

And why are you using prehistorical OpenGL? Or are you stuck with good-for-nothing video card (like I am)?

0

Share this post


Link to post
Share on other sites

So what is the issue?

The first image shows the issue: when I draw points on the left half of the screen it seems to decide to skip a few columns. It's an 800x600 window and I'm drawing 800x600 points.

 

Second and third images show me drawing my rasterizer to a localized region of the window (400x300 points).

 

--

In:

int x = i % m_bufferWidth;
int y = i / m_bufferWidth;
int halfWidth = m_bufferWidth / 2;
int halfHeight = m_bufferHeight / 2;


Shouldn't it be:

int y = i / m_bufferHeight;

 

No, as it is an array that I am indexing. As such, the rows are calculated as (i / width).

 

--

And why are you using prehistorical OpenGL? Or are you stuck with good-for-nothing video card (like I am)?

 

Because I was referencing openGL books I had on hand.

 

--

It's just frustrating that I tell the thing to render 800x600 points and it apparently gets lazy halfway through.

0

Share this post


Link to post
Share on other sites

Is there a reason you're drawing all those vertices? Wouldn't it be easier to create a texture and render it on a fullscreen quad?

0

Share this post


Link to post
Share on other sites

Is there a reason you're drawing all those vertices? Wouldn't it be easier to create a texture and render it on a fullscreen quad?

 

From what I saw, rendering to a texture was about as equivalent to rendering to the screen. i.e. you just targeted a different framebuffer that was bound to a texture.

 

Maybe I missed something?

0

Share this post


Link to post
Share on other sites

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). Edited by tanzanite7
0

Share this post


Link to post
Share on other sites

All right, got it fixed. It's been too long since I last touched graphics stuff so I forgot about the whole 0.5 pixel location thing. Which is one of the reasons that I'm doing this... experiment.

 

And yes, I realize that pushing to a texture and rendering a quad is the better solution but when I looked for how to do this, all I got was this whole binding a frame buffer to a texture and doing the draw calls to that. Ergo, it seemed pointless to go that route.

 

Thanks.

Edited by telaryus
0

Share this post


Link to post
Share on other sites

And yes, I realize that pushing to a texture and rendering a quad is the better solution but when I looked for how to do this, all I got was this whole binding a frame buffer to a texture and doing the draw calls to that. Ergo, it seemed pointless to go that route.

 

You probably want something like this:

// Initialization
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

// Updating
glBindTexture(GL_TEXTURE_2D, texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);

// Rendering
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0,1); glVertex2f(-1, -1);
glTexCoord2f(1,1); glVertex2f( 1, -1);
glTexCoord2f(1,0); glVertex2f( 1,  1);
glTexCoord2f(0,0); glVertex2f(-1,  1);
glEnd();

 

Hopefully got all that correct because I just typed it in there :p And that "pixels" is your "m_renderBuffer".

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0