• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# OpenGL OpenGL Selection Hates My Code!

## Recommended Posts

I have been able to use selection while drawing basic primitives but when I try it with my class that loads an MD2 file no matter how big or where on the screen the model is drawn it always says the mouse cursor is on top. I project the 3D Model so it can be drawn inside a 2D box and whenever I use this method is when stuff doesn''t work. Here''s the code that calculates the projection. void LoadMD2::Draw2D(int X,int Y,int Width,int Height,float D) { float XDist,YDist,XRatio,YRatio; Vectors3f Top,Bottom,Left,Right,Pos; glPushMatrix(); glLoadIdentity(); //================= // D is Depth // MouseToOpenGL converts 2D coords to 3D Top=MS.MouseToOpenGL(X+(Width/2),Y+Height,D); Bottom=MS.MouseToOpenGL(X+(Width/2),Y,D); Left=MS.MouseToOpenGL(X,Y+(Height/2),D); Right=MS.MouseToOpenGL(X+Width,Y+(Height/2),D); Pos=MS.MouseToOpenGL(X+(Width/2),Y+(Height/2),D); XDist=Left.Distance(Right); // Width of bounding area in 3D space YDist=Top.Distance(Bottom); // Height of bounding area XRatio=XDist/Model.ModelDimensions.X; // calculate how much YRatio=YDist/Model.ModelDimensions.Y; // to scale model to fit // choose lowest scale val so we keep scale proportional if(YRatio < XRatio) XRatio=YRatio; //===================== glTranslatef(Pos.X,Pos.Y,Pos.Z); glScalef(XRatio,XRatio,XRatio); Draw(); // draw Model glPopMatrix(); }

##### Share on other sites
It seems like whenever I use my MouseToOpenGL function while drawing something is when it doesn''t work.

I drew a line,triangle,quad,pentagon and sphere all using this
function and it did the same thing but when I typed in the vertices for the triangle by hand selection would work right with the triangle.

The function looks like this:

Vectors3f MouseShit::MouseToOpenGL(int X,int Y,float Z)
{
// DO NOT call this between glBegin & glEnd
GLdouble TempX;
GLdouble TempY;
GLdouble TempZ;
GLint Viewport[4];
GLdouble ModelView[16];
GLdouble Projection[16];
glGetDoublev(GL_MODELVIEW_MATRIX,ModelView);
glGetDoublev(GL_PROJECTION_MATRIX,Projection);
glGetIntegerv(GL_VIEWPORT,Viewport);
gluUnProject((GLdouble)X,(GLdouble)Y,(GLdouble)Z, ModelView,Projection,Viewport,&TempX,&TempY,&TempZ);
Vectors3f TempV((float)TempX,(float)TempY,(float)TempZ);
return(TempV);
}

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627657
• Total Posts
2978466
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33