Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
krysmopompas
Jan 17, 2004
hi

OneEightHundred posted:

I really don't get this, there isn't really any reason that throwing calls into a work queue would do anything about the overhead of making those calls.
There are a lot of reasons, the paper covers that. There's an additional presentation on the same subject from this year's gdc by some atvi guy that I haven't noticed out in the wild yet too.

OneEightHundred posted:

Incidentally this sort of thing isn't even new, Quake 3 did it.
Using opengl display lists is certainly an inventive way of bypassing d3d9's overhead.

Adbot
ADBOT LOVES YOU

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

krysmopompas posted:

There are a lot of reasons, the paper covers that. There's an additional presentation on the same subject from this year's gdc by some atvi guy that I haven't noticed out in the wild yet too.
The only thing it seems to address is utilization, I really don't get why a D3D call would be cheaper in their approach.

quote:

Using opengl display lists is certainly an inventive way of bypassing d3d9's overhead.
It doesn't use display lists, it queues backend commands and runs them and another thread eats them and sends them to OpenGL. I mean it's basically the same approach.

Poor Communist
Feb 20, 2008
e: nevermind.

Poor Communist fucked around with this message at 08:17 on Mar 29, 2010

Bitruder
Nov 29, 2003

Majoring in connect the dots and colouring
Over on Reddit a guy is posting his modern OpenGL tutorial and so far it seems pretty great. Here's the the table of contents. So far he only has a few chapters out, but he's been churning out new ones almost every day.

http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Bitruder posted:

Over on Reddit a guy is posting his modern OpenGL tutorial and so far it seems pretty great. Here's the the table of contents. So far he only has a few chapters out, but he's been churning out new ones almost every day.

http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html
This looks pretty good so far! I really hope this guy keeps it up - it's appalling how out of date the canonical OpenGL tutorials are.

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
I'm having an issue with rotating a matrix.

Over time my matrix seems to get wonky and my object will get skewed. I'm pretty sure it's not a problem with my math, but how should I go about avoiding this? The faster / more it rotates, the faster it distorts.

http://www.mediafire.com/?4h2ljzmymcm

haveblue
Aug 15, 2005
Probation
Can't post for 2 hours!
Toilet Rascal

slovach posted:

I'm having an issue with rotating a matrix.

Over time my matrix seems to get wonky and my object will get skewed. I'm pretty sure it's not a problem with my math, but how should I go about avoiding this? The faster / more it rotates, the faster it distorts.

http://www.mediafire.com/?4h2ljzmymcm

Don't repeatedly add small incremental rotations to the same matrix, store the angle as a float and regenerate the whole matrix each time.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Alternately use a quaternion for orientation since you can just renormalize it to prevent floating point error from accumulating.

Rav
Nov 5, 2000

krysmopompas posted:

As a side-note, if you want to get fancy, http://www.emergent.net/GameFest2008 is an interesting way of bypassing the draw call limitations.

DirectX 9 also supports state blocks which are pretty much the same thing as opengl draw lists. If I recall, they also added a method for generalized command buffer building, but that might only be for the consoles.


slovach posted:

I'm having an issue with rotating a matrix.

Over time my matrix seems to get wonky and my object will get skewed. I'm pretty sure it's not a problem with my math, but how should I go about avoiding this? The faster / more it rotates, the faster it distorts.


Alternatively, if you must use your matrices and they are orthogonal, you can always reorthognalize them. There are a few methods, (taking the cross product of x,y, then x,y... Gram Schmitt method, etc). But the methods stated in the above posts are probably the best unless you have an extenuating circumstance that you didnt mention.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
I'm guessing this has probably been asked as one point or another in this thread, but I can't seem to find anything about this so here goes:

What's a good book for learning Direct3D 10? For reference, I have a CS degree and I've taken a graphics class which covered the theoretical side of things with some OpenGL-based assignments and I've gone through a good chunk of the Red Book. It's really a matter of learning D3D10 itself. Problem is, the tutorials on MSDN aren't nearly enough and the reference documentation isn't exactly the ideal learning material.

Ideally, I'd want something like the Red Book in terms of presentation, but for D3D10. It doesn't have to be a book, but that's roughly the length I'd expect it to be.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
Check out 'Introduction to 3D Game Programming with DirectX 10' by Frank Luna.

He does a pretty good job at explaining things in a logical sequence, and unlike most books with 'Game Programming' in the title he doesn't pull too many mathematical punches and provides the actual formulas for doing 3D operations.

My only real complaint about this book is that the author tends to introduce and discuss tiny code snippets one by one, so you need to download the examples off his website to get a big picture view of how everything works together.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
Alright, I went ahead and ordered a copy. Thanks.

Whilst farting I
Apr 25, 2006

For OpenGL and C++, I'm trying to clip this polygon using the Cohen-Sutherland algorithm.



The way it should be clipped is that when the user selects a region using the mouse, the polygon should be displayed ONLY within that specified rectangular region (that black horizontal line is a test line I had for the algorithm to make sure it clips properly - it should go all the way across the screen if not clipped).



If the program worked as intended, then the only bits of the polygon you'd see would be displayed within the pink region, and everything outside of that region would not be displayed.

The only problem is that the way I'm displaying this polygon right now is manually connecting every single line segment, like so.

code:
glBegin(GL_LINE_STRIP);

    glVertex2i(120, 230);
    glVertex2i(370, 230);

    // repeat like 15 more times

glEnd();
And the way I'm displaying that test line seems to be very not conducive to what I'm trying to do.

Upon the last mouse click, indicating that the user has finished selecting the region, global variable twoClicks is set equal to true, and this part of the template function in the display function thus gets called.

code:
void templateDraw()
{
	// user has finished selecting region
	if (clickNum%2 == 0)
	{
		// draws purple region
		drawRegion();
		
		// to avoid infinite loop, only calculate new endpoints once
		if (twoClicks)
		{
			chAlg(1,250,499,250);
			twoClicks = false;
		}

		// if the line hasn't been trivially rejected, then draw it
		if (!trivReject)
		{
			glBegin(GL_LINES);
				glColor3f(0.0, 0.0, 0.0);
				glVertex2i(tempsX, tempsY);
				glVertex2i(tempeX, tempeY);
			glEnd();
		}
	}
}
All of those "temp" variables are more global variables. The chAlg function sets them equal to the final, clipped points - so 1,250,499,250 are clipped and those clipped variables are then stored in the temps.

This only supports one line segment at a time.

I have no idea whatsoever how to apply this to an entire polygon, especially when I'm using all those glVertex statements to draw it. I'm using a timer, so keeping everything on screen is really tough. :( Any suggestions would be greatly appreciated. All I can think of would be a global array with 64 points that'd all have to be calculated. :psyduck:

cliffy
Apr 12, 2002

Whilst farting I posted:

For OpenGL and C++, I'm trying to clip this polygon using the Cohen-Sutherland algorithm.

I think I found your problem.

I'm not a graphics expert by any means, so I may be about to shove my foot in my mouth, BUT:

Wikipedia posted:

In computer graphics, the Cohen–Sutherland algorithm is a line clipping algorithm.

A line clipping algorithm.

Maybe you want this instead:
http://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman

I guess you can clip all the lines using the limits set by the bounding box that is drawn, but you're not going to have a well defined polygon anymore. Maybe you are just abusing the term 'polygon' and you meant a collection of lines that just happen to share endpoints.

Here's what I'd do:

code:
#include <vector>

struct Line
{
   Line(int x1, y1, m_x2, m_y2) :
      m_x1 (x1),
      m_y1 (y1),
      m_x2 (x2),
      m_y2 (y2)
   {
      //FIXME: Check and swap endpoints here if they need to be in a particular order. Like if x1 < x2 must be true.
   }
   int m_x1, m_y1,
       m_x2, m_y2;
};

std::vector<Line> gLines;
int gMouseX, gMouseY; 
int gX1, gY1, gX2, gY2;

void cohenSutherland(Line& l, int xMin, int yMin, int xMax, int yMax)
{
   //Implement.
}

void OnMouseMove(int x, int y)
{
   //FIXME: I'm assuming no translation between mouse coords and world coords, but that is probably wrong...
   gMouseX = x;
   gMouseY = y;
}

void OnMouseButton(...)
{
   //if left button down
      gX1 = gMouseX;
      gY1 = gMouseY;
   //else if left button up
      {
         gX2 = gMouseX;
         gY2 = gMouseY;
         //swap points if gX1 needs to be less than gX2, etc.
         for (std::vector<Line>::iterator it = gLines.begin();
               it != gLines.end();
               ++it)
         {
            cohenSutherland(*it, gX1, gY1, gX2, gY2);
         }
      }
}
Of course you need to fill in some important details.

Whilst farting I posted:

I have no idea whatsoever how to apply this to an entire polygon, especially when I'm using all those glVertex statements to draw it. I'm using a timer, so keeping everything on screen is really tough. Any suggestions would be greatly appreciated. All I can think of would be a global array with 64 points that'd all have to be calculated.

Again, if need to apply this to a 'polygon' you need to look elsewhere, like: http://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman

I don't understand why you are using a timer or what it could be possibly used for. How would that make drawing to the screen tougher? It sounds like your main problem is how to structure the code/solution so its clear and easy to work with. When you apply a little structure/planning this:

code:
glBegin(GL_LINE_STRIP);

    glVertex2i(120, 230);
    glVertex2i(370, 230);

    // repeat like 15 more times

glEnd();
becomes

code:
#include <algorithm>

void drawLine(Line& l)
{
    glBegin(GL_LINE_STRIP);
        glVertex2i(l.m_x1, l.m_y1);
        glVertex2i(l.m_x2, l.m_y2);
    glEnd();
}

std::for_each(gLines.begin(), gLines.end(), drawLine);
That help or make any sense?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Sutherland–Hodgman can be simplified in the case of convex windings because you can guarantee there will never be more than 2 intersection points per plane. i.e.:

code:
for each bounding plane on the volume:
    find which two lines on the winding intersect with the bounding plane
    for each intersection point:
        if the intersection is at the end of the line:
            use the line endpoint as the intersection point
        else:
            generate a new point at the intersection
    connect the intersection points
    discard any points on the external side of the bounding plane

Screeb
Dec 28, 2004

status: jiggled

Whilst farting I posted:

For OpenGL and C++, I'm trying to clip this polygon using the Cohen-Sutherland algorithm.

What exactly is your objective? Is it just to use that algorithm? Or are you just wanting to clip something? If it's the latter, then you can simply use the glClipPlane function.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.


I'm trying to make a set of XYZ axes that float in the corner of the viewing area to provide some sense of direction while navigating around a scene. In the image above the large set of axes is an object in world space that is sitting at the origin and the colored lines are unit vectors with RGB <=> XYZ. The little set of axes in the lower-left corner is a similar object, but scaled and translated so that it is always sitting in front of the camera's near plane.

The problem I'm running into is that the little axes aren't centered in the middle of the view space so the projection transform is causing them to be drawn with a slight tilt. Ideally, the big and little axes in the image above would have an identical orientation.

Is there any easy way to get rid of this unwanted projection tilt? I suppose I could render the little axes to their own texture and then draw it as a sprite on top of the rest of the image, but it just feels like there's a simpler solution that I'm missing.

PDP-1 fucked around with this message at 19:00 on Apr 17, 2010

haveblue
Aug 15, 2005
Probation
Can't post for 2 hours!
Toilet Rascal

PDP-1 posted:

Is there any easy way to get rid of this unwanted projection tilt? I suppose I could render the little axes to their own texture and then draw it as a sprite on top of the rest of the image, but it just feels like there's a simpler solution that I'm missing.

Rather than setting up a whole new framebuffer, you can just change the viewport to a small rectangle in the corner and then the perspective will look correct.

However, you probably also want to draw the axes with an orthographic projection to eliminate all distortion permanently.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
That worked brilliantly. Thank you.

hey mom its 420
May 12, 2007

What's a good 3ds loader for OpenGL? I'm starting out with OpenGL and right now I want to load a 3ds model and have it rotate a bit. What would be the best way to do this? Keep in mind that I'm pretty much a noob when it comes to all this. Oh yeah, I'm coding in C++.

hey mom its 420 fucked around with this message at 19:46 on Apr 18, 2010

Contero
Mar 28, 2004

What is the difference between pixel buffer objects and render buffer objects. I'm trying to render something offscreen and I looks like I can use either. What are their advantages/disadvantages? Is one more dated than the other?

Screeb
Dec 28, 2004

status: jiggled

Bonus posted:

What's a good 3ds loader for OpenGL? I'm starting out with OpenGL and right now I want to load a 3ds model and have it rotate a bit. What would be the best way to do this? Keep in mind that I'm pretty much a noob when it comes to all this. Oh yeah, I'm coding in C++.

Check out Assimp. That'll load the file for you. You'll have to loop through the resulting data and draw it yourself, but it's a start.

heeen
May 14, 2005

CAT NEVER STOPS

Contero posted:

What is the difference between pixel buffer objects and render buffer objects. I'm trying to render something offscreen and I looks like I can use either. What are their advantages/disadvantages? Is one more dated than the other?

As far as I know, PBOs require a context switch to render to and are slower because of this. I think the data you copy into a texture subsequently also has to travel over the bus.
All the cool kids use FBOs nowadays. Plus you can use multiple render targets etc.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm writing a software renderer in Java. When it comes to implementing a camera, I am thinking about simply having a point in space (the camera) with a target to view, then shooting rays from the camera to draw to the scene. This sound like it would work (and an early test shows it does). However, this goes against what I learned a long while back -- that you should have your camera at <0,0,0> and then translate all the objects in the world by -cameraX,-cameraY,-cameraZ, applying a projection matrix afterwards.

Is one of these approaches preferable to the other?

Contero
Mar 28, 2004

Well I've just spent a bunch of time trying to get FBOs to work and the most random thing seems to be causing the error. If I don't enable mipmaps for the texture I'm rendering into, I get a GL_FRAMEBUFFER_UNSUPPORTED_EXT error when I check the status. Even stranger, I've tried this code on 4 machines and both nvidia machines throw the error and both ati machines handle it just fine. Does anyone have any idea why this is happening?

code:
   glewInit();
   if ( ! glewIsSupported("GL_EXT_framebuffer_object") )
      quitError("GL_EXT_framebuffer_object not supported.\n");

   GLuint fbo, tex;

   glGenFramebuffersEXT(1, &fbo);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

   glGenTextures(1, &tex);
   glBindTexture(GL_TEXTURE_2D, tex);
   glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // False here causes error
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
   
   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);

   GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
   if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
      printf("Framebuffer set up correctly.\n");
   else {
      printf("Framebuffer did not set up correctly with status: %x\n", status);
      return 0;
   }
Honestly I'm getting pretty sick of opengl. Think I'll start diving into directx pretty soon.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Jo posted:

I'm writing a software renderer in Java. When it comes to implementing a camera, I am thinking about simply having a point in space (the camera) with a target to view, then shooting rays from the camera to draw to the scene. This sound like it would work (and an early test shows it does). However, this goes against what I learned a long while back -- that you should have your camera at <0,0,0> and then translate all the objects in the world by -cameraX,-cameraY,-cameraZ, applying a projection matrix afterwards.

Is one of these approaches preferable to the other?

If your camera moves far enough away from the origin, you'll start seeing rendering errors because the precision of float-point numbers drops as you move further from the origin.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Contero posted:

Well I've just spent a bunch of time trying to get FBOs to work and the most random thing seems to be causing the error.
For NVIDIA, use GLExpert to get better error info.

Try a different format (i.e. not GL_RGBA8)

Try glGenerateMipmapEXT(tex)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Contero posted:

Honestly I'm getting pretty sick of opengl. Think I'll start diving into directx pretty soon.
You'll find it's pretty much equally stupid.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Yeah dealing with pixel format validity in D3D is just as obnoxious.

Once you start running into issues caused by lovely driver GLSL compilers, THEN you'll have a real reason to ragequit OpenGL!

hey mom its 420
May 12, 2007

I'm going to implement a simple 3D racing with bullet and OpenGL. What's the best way to move the camera around -- manually doing the transformations with glRotate and friends or using gluLookAt?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Either will work but I wouldn't say either is the best practice. You should learn how matrices (and quaternions, another important construct for rotations) work and just send a complete matrix.

Especially since D3D doesn't give you either of those.

hey mom its 420
May 12, 2007

I know how matrices work and I have an idea of how I'd be able to implement my own gluLookAt by just using transformations. Quaternions still baffle me though, gonna have to look them up.

shodanjr_gr
Nov 20, 2007
Can anyone recommend a "robust" camera class/mini-library with the ability to switch between arcball/flythrough manipulation modes etc. on the fly?

Contero
Mar 28, 2004

To continue the theme of me complaining about FBOs and OpenGL, why, oh why would the clear color be used as the draw color when I'm rendering into an FBO?


Click here for the full 1040x806 image.


The clear color I'm using in the FBO is (1,1,1,0.5). When I'm drawing the actual object I explicitly set all materials and color to white or some shade of white (for ambient).

When I set the clear color to solid yellow I get this:


Click here for the full 1040x678 image.


But if I take that same rendering code and remove the binds for the FBO it looks like this, which is what it should look like:


Click here for the full 1040x806 image.


What the hell?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Somewhat relevant since I bet most people here will run into this the instant they try doing normalmapping:

I've seen the question of how to generate tangent-space vectors for a mesh (or more specifically, the triangles on the mesh) come up a lot in various places. Incidentally, the most commonly-cited algorithm is wrong about forcing them to be orthogonal, and wrong about how they should be generated in the first place.

So, I've posted an article detailing why it's wrong, how to correctly calculate them, the math behind it, and of course, source code.

Contero posted:

To continue the theme of me complaining about FBOs and OpenGL, why, oh why would the clear color be used as the draw color when I'm rendering into an FBO?
Are you sure it's not using the draw color when it's drawing that quad with the FBO result as the texture? That would give you essentially the same result, i.e. on the yellow one, the white parts in the texture would become colorized yellow.

OneEightHundred fucked around with this message at 03:56 on Apr 23, 2010

Contero
Mar 28, 2004

OneEightHundred posted:

Are you sure it's not using the draw color when it's drawing that quad with the FBO result as the texture? That would give you essentially the same result, i.e. on the yellow one, the white parts in the texture would become colorized yellow.

The reason I'm sure is in the first picture, which I forgot to mention. When I have the clear color set to 0.5 alpha, you can see where the object overlaps itself, which wouldn't be possible if it were just drawing the quad that color.

Also before you said try another format other than RGBA8, what would you suggest? I thought that would be a pretty normal/standard color format for a texture.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Contero posted:

The reason I'm sure is in the first picture, which I forgot to mention. When I have the clear color set to 0.5 alpha, you can see where the object overlaps itself, which wouldn't be possible if it were just drawing the quad that color.
Well, yes, but the quad is also kind of light blue tinted which is the main background so maybe it's doing both?

quote:

Also before you said try another format other than RGBA8, what would you suggest? I thought that would be a pretty normal/standard color format for a texture.
Try RGB8, I think I've heard that certain hardware gets bitchy over trying to render to a texture with an alpha channel under certain conditions (I think the jist was that some hardware requires all render targets in a context to be the same format?), but definitely download GLExpert, it will actually give you a reason that you're getting UNSUPPORTED_FORMAT.

Glimm
Jul 27, 2005

Time is only gonna pass you by

This question might belong more in the C++ thread but here goes:

I am iterating over a list of a Shape class I created and attempting to update each object with some transformations, all I'm working on so far is updating the angle of rotation (for animation purposes):

code:
	while(itr != shapes.end()) {		
			Shape p = *itr;
			p.transform();
			itr++;
	}
Inside my transform method all I have is:

code:
	if (localrotate != 0) {
		//cout << "Local rotate " << theta << " degrees." << endl;	
		glRotatef(theta * localrotate, 0.0, 0.0, 1.0);
		theta += mod;
	}
For some reason theta does not get updated the next time I pull p out of the list, should I be popping the list until it is empty, updating, then putting the Shapes back on the list? Or am I missing something else?

Glimm fucked around with this message at 22:35 on Apr 23, 2010

Nippashish
Nov 2, 2005

Let me see you dance!

Glimm posted:

code:
while(itr != shapes.end()) {		
	Shape p = *itr;
	p.transform();
	itr++;
}

You're making a copy of each shape and transforming the copy.

Edit: To be a bit more helpful, what you want to do is

code:
while(itr != shapes.end()) {		
	itr->transform();
	itr++;
}

Adbot
ADBOT LOVES YOU

Glimm
Jul 27, 2005

Time is only gonna pass you by

Nippashish posted:

You're making a copy of each shape and transforming the copy.

Edit: To be a bit more helpful, what you want to do is

code:
while(itr != shapes.end()) {		
	itr->transform();
	itr++;
}

Thanks, I'm retarded :( I wish more of my earlier coursework had been in C++.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply