Beispiel #1
0
void ProcessSelection(int xPos, int yPos)
{

  static GLuint selectBuff[BUFFER_LENGTH];
  GLint hits, viewport[4];
  glSelectBuffer(BUFFER_LENGTH, selectBuff);
  glGetIntegerv(GL_VIEWPORT, viewport);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glRenderMode(GL_SELECT);
  glLoadIdentity();
  gluPickMatrix(xPos, viewport[3] - yPos + viewport[1], 2,2, viewport);
  gluPerspective(60.0f, fAspect, 1.0, 1000.0);
  DrawObjects();
  hits = glRenderMode(GL_RENDER);
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  if(hits == 1)
    {
      MakeSelection(selectBuff[3]);
      if(selectedObject == selectBuff[3])
	selectedObject = 0;
      else
	selectedObject = selectBuff[3];
    }

  printf("holaaaaa donde estoy en %d , %d\n", xPos, yPos);

  glutPostRedisplay();
}
Beispiel #2
0
void handleSelection(int x, int y)
{
	glInitNames();
	GLuint hitBuffer[64] = {0};
	glSelectBuffer(64, hitBuffer);
	glRenderMode(GL_SELECT);
	GLint vp[4];
	glGetIntegerv(GL_VIEWPORT,vp);
 	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluPickMatrix(x,currentRes[1]-y,5.0,5.0,vp);
	gluPerspective(45.0,RESOLUTION_X/RESOLUTION_Y, 0.5, 50.0);
	glScalef((float)RESOLUTION_X/currentRes[0], (float)RESOLUTION_Y/currentRes[1], 1.0);
  
	glMatrixMode(GL_MODELVIEW);
	renderScene();
	glMatrixMode(GL_PROJECTION);
  
  	glPopMatrix();
  	glFlush();
  	GLint hitCount = glRenderMode(GL_RENDER);
  	listSelected(hitCount, hitBuffer);
	glMatrixMode(GL_MODELVIEW);
}
Beispiel #3
0
Block *
click(int x, int y, int *face)
{
	GLuint  buffer[BUFFER_SIZE];
	GLint	viewport[4];
	GLint  hits;

	glGetIntegerv(GL_VIEWPORT, viewport);
	glSelectBuffer(BUFFER_SIZE, buffer);

	glRenderMode(GL_SELECT);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3]-y), 1.0f, 1.0f, viewport);

	gluPerspective(FOV, (GLfloat) (WINDOW_WIDTH/WINDOW_HEIGHT), Z_NEAR, Z_FAR);
	glMatrixMode(GL_MODELVIEW);
	redraw_world();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);
	hits=glRenderMode(GL_RENDER);

	return processHits(hits, buffer, face);
}
std::vector<GUIGlID>
GUISUMOAbstractView::getObjectsInBoundary(const Boundary& bound) {
    const int NB_HITS_MAX = 1024 * 1024;
    // Prepare the selection mode
    static GUIGlID hits[NB_HITS_MAX];
    static GLint nb_hits = 0;
    glSelectBuffer(NB_HITS_MAX, hits);
    glInitNames();

    Boundary oldViewPort = myChanger->getViewport(false); // backup the actual viewPort
    myChanger->setViewport(bound);
    applyGLTransform(false);

    // paint in select mode
    int hits2 = doPaintGL(GL_SELECT, bound);
    // Get the results
    nb_hits = glRenderMode(GL_RENDER);
    if (nb_hits == -1) {
        myApp->setStatusBarText("Selection in boundary failed. Try to select fewer than " + toString(hits2) + " items");
    }
    std::vector<GUIGlID> result;
    for (int i = 0; i < nb_hits; ++i) {
        assert(i * 4 + 3 < NB_HITS_MAX);
        result.push_back(hits[i * 4 + 3]);
    }
    // switch viewport back to normal
    myChanger->setViewport(oldViewPort);
    return result;
}
    void gl_select(int x, int y){
        GLuint buff[64] = {0};
        GLint hits, view[4];

        glSelectBuffer(64, buff);

        glGetIntegerv(GL_VIEWPORT, view);

        glRenderMode(GL_SELECT);

        glInitNames();

        glPushName(0);

        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        gluPickMatrix(x,y,1.0,1.0,view);
        gluPerspective(45,1.0,0.0001,1000.0);

        glMatrixMode(GL_MODELVIEW);

        glutSwapBuffers();
        draw();

        glMatrixMode(GL_PROJECTION);
        glPopMatrix();

        hits = glRenderMode(GL_RENDER);

        list_hits(hits,buff);

        glMatrixMode(GL_MODELVIEW);
    }
Beispiel #6
0
TokenId KPboardView::Selection(const Camera &camera, int x, int y) const
{
    GLuint  buffer[BUF_SIZE]; // Set Up A Selection Buffer
    auto choose = TokenId::EMPTY;

    glSelectBuffer(BUF_SIZE, buffer);
    glRenderMode(GL_SELECT); // Change to Selection mode
    glInitNames();
    glPushName(0); // Push 0 (At Least One Entry) Onto The Stack

    camera.Draw(x, y);
    Draw(true); // Draw the tokens (not the board)

    auto hits = glRenderMode(GL_RENDER);  // Change back to render mode

    if (hits > 0)
    {
        choose = static_cast<TokenId>(buffer[3]);
        auto depth = buffer[1];

        for (auto loop = 1; loop < hits; loop++)
        {
            if (buffer[loop * 4 + 1] < GLuint(depth))
            {
                // store the closest object
                choose = static_cast<TokenId>(buffer[loop * 4 + 3]);
                depth  = buffer[loop * 4 + 1];
            }
        }
    }

    return choose;
}
Beispiel #7
0
bool C3dView::BeginSelect ( int x, int y )
{
	if (m_bDrawing )
		return false;

	m_bDrawing = true;
	m_bOverlayMode = false;
	m_bForcedDrawing = false;

	GLint	viewport[4] = {0};
	
	memset(m_uiSelectBuf,0,sizeof(GLuint)*_SEL_BUFFER_SIZE);
	glGetIntegerv(GL_VIEWPORT, viewport);

	glSelectBuffer(_SEL_BUFFER_SIZE, m_uiSelectBuf);
	glRenderMode(GL_SELECT);

	glInitNames();
	glPushName(0xffffffff);

	glMatrixMode(GL_PROJECTION);

	glPushMatrix();
	glLoadIdentity();
	gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),2.0, 2.0, viewport);
	gluPerspective (m_fov,m_fAspect,m_xNearZ,m_xFarZ);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	SetInitalMatrix();

	return true;
}
Beispiel #8
0
static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpointer _)
{
	gdouble height = GTK_WIDGET(opengl)->allocation.height;
	gdouble gl_x   = event->x;
	gdouble gl_y   = height - event->y;

	/* Configure view */
	gint viewport[4];
	gdouble projection[16];
	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetDoublev(GL_PROJECTION_MATRIX, projection);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluPickMatrix(gl_x, gl_y, 2, 2, viewport);
	glMultMatrixd(projection);

	/* Prepare for picking */
	guint buffer[100][4] = {};
	glSelectBuffer(G_N_ELEMENTS(buffer), (guint*)buffer);
	glRenderMode(GL_SELECT);
	glInitNames();

	/* Run picking */
	g_mutex_lock(opengl->objects_lock);
	GPtrArray *objects = _objects_to_array(opengl);
	for (guint i = 0; i < objects->len; i++) {
		glPushName(i);
		GritsObject *object = objects->pdata[i];
		object->state.picked = FALSE;
		grits_object_pick(object, opengl);
		glPopName();
	}
	int hits = glRenderMode(GL_RENDER);
	g_debug("GritsOpenGL: on_motion_notify - hits=%d ev=%.0lf,%.0lf",
			hits, gl_x, gl_y);
	for (int i = 0; i < hits; i++) {
		//g_debug("\tHit: %d",     i);
		//g_debug("\t\tcount: %d", buffer[i][0]);
		//g_debug("\t\tz1:    %f", (float)buffer[i][1]/0x7fffffff);
		//g_debug("\t\tz2:    %f", (float)buffer[i][2]/0x7fffffff);
		//g_debug("\t\tname:  %p", (gpointer)buffer[i][3]);
		guint        index  = buffer[i][3];
		GritsObject *object = objects->pdata[index];
		object->state.picked = TRUE;
	}
	for (guint i = 0; i < objects->len; i++) {
		GritsObject *object = objects->pdata[i];
		grits_object_set_pointer(object, object->state.picked);
	}
	g_ptr_array_free(objects, TRUE);
	g_mutex_unlock(opengl->objects_lock);

	/* Cleanup */
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	return FALSE;
}
Beispiel #9
0
bool Renderer::offsetOnPoint(int x, int y, int& out) 
{
	GLuint buf[256];
	glSelectBuffer(256, buf);
	glRenderMode(GL_SELECT);
	setProjectionMatrix(true, x, y);
	glInitNames();
	drawScene(true);
	GLint hits = glRenderMode(GL_RENDER);
	setProjectionMatrix();
	GLuint *p = buf;
	GLuint minZ = INFINITE;
	GLuint selectedName = 0;
	for (int i=0; i < hits; i++){
		GLuint names = *p; p++;
		GLuint z = *p; p++; p++;
		if ((names > 1) && (z < minZ) && (*p == SELECTION_COVERS)){
			minZ = z;
			selectedName = *(p+1);
		}
		p += names;
	}
	if (minZ != INFINITE){
		out = (selectedName - SELECTION_CENTER);
		return true;
	} else {
		return false;
	}
}
Beispiel #10
0
/* Initialize material property and light source. */
void
myinit(void)
{
  GLfloat light_ambient[] =
  {0.2, 0.2, 0.2, 1.0};
  GLfloat light_diffuse[] =
  {1.0, 1.0, 1.0, 1.0};
  GLfloat light_specular[] =
  {1.0, 1.0, 1.0, 1.0};
  GLfloat light_position[] =
  {1.0, 1.0, 1.0, 0.0};

  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  glEnable(GL_LIGHT0);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);

  glSelectBuffer(BUFSIZE, selectBuf);

  glNewList(TORUS, GL_COMPILE);
  glutSolidTorus(0.275, 0.85, 10, 15);
  glEndList();
  glNewList(TETRAHEDRON, GL_COMPILE);
  glutSolidTetrahedron();
  glEndList();
  glNewList(ICOSAHEDRON, GL_COMPILE);
  glutSolidIcosahedron();
  glEndList();
}
Beispiel #11
0
void mouse(int button, int state, int x, int y) {
    if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return;

    GLuint select_buf[BUFSIZE];
    GLint hits;
    GLint viewport[4];

    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(BUFSIZE, select_buf);

    (void) glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    gluPickMatrix((GLdouble) x, (GLdouble) viewport[3] - y, 20.0, 20.0, viewport);
    gluPerspective(45.0, width / (double) height, .2, 200.0);

    scene.render(true);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();

    hits = glRenderMode(GL_RENDER);

    if (hits != 0) processHits(hits, select_buf);

    glutPostRedisplay();
}
Beispiel #12
0
void Engine::init()
{
	// Create the main window
	app = new sf::Window(sf::VideoMode(800, 600, 32), "3DS Loader");

	// Create a clock for measuring time elapsed
	clock = new sf::Clock;

	model = new Model3DS(cfg::modelName);
	if (!model->load("test.3ds")) {
		cout << "Can't find model file!" << endl;
		exit(1);
	}
	
	glSelectBuffer(cfg::selectBufferSize, selectBuffer);

	// Set color and depth clear value
	//glClearDepth(1.f);
	glClearColor(0.f, 0.f, 0.f, 1.f);

	// Enable Z-buffer read and write
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	
	// Light
	glEnable(GL_LIGHTING);
	
	glLightfv(GL_LIGHT0, GL_AMBIENT, cfg::ambientColor);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, cfg::diffuseColor);
	glLightfv(GL_LIGHT0, GL_SPECULAR, cfg::specularColor);

	glEnable(GL_LIGHT0);
}
Beispiel #13
0
void
Setup3dSelect ( Viewer3dParam *par, GLuint *buffer, int cursorX, int cursorY )
{
        GLint viewport[4];
        glSelectBuffer(SELECT_BUFSIZE, buffer);
        glRenderMode(GL_SELECT);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
        glGetIntegerv(GL_VIEWPORT,viewport);
        gluPickMatrix(cursorX,viewport[3]-cursorY,
			5,5,viewport);
        
        float ratio = 1.386;

         gluPerspective(par->fov, ratio, par->zNear, par->zFar);

         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
         gluLookAt(par->eye[0],par->eye[1],par->eye[2],
                   par->unit[0],par->unit[1],par->unit[2],
                   par->up[0],par->up[1],par->up[2]);

         glInitNames();
}
Beispiel #14
0
void selectObject(x, y) {
	GLuint selectBuffer[BUFSIZE];
	GLint hitsNumber;
	GLint viewPort[4];

	glGetIntegerv(GL_VIEWPORT, viewPort);
	glSelectBuffer(BUFSIZE, selectBuffer);
	(void) glRenderMode(GL_SELECT);
	glInitNames();
	glPushName(0);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glGetIntegerv(GL_VIEWPORT, viewPort);
	gluPickMatrix(x, y, 1.0, 1.0, viewPort);
	gluPerspective(45.0, 1.0, 1.0, 1000.0);
	glMatrixMode(GL_MODELVIEW);
	glutSwapBuffers();
	display();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	hitsNumber = glRenderMode(GL_RENDER);
	glFlush();
	glutPostRedisplay();
	processSelectedObject(hitsNumber, selectBuffer);
}
Beispiel #15
0
int SubdivScene::select(int x, int y, int width, int height, float fovy, Face* f) {
    GLuint buffer[SELECT_BUFFER_SIZE];
    glSelectBuffer(SELECT_BUFFER_SIZE, buffer);
    glRenderMode(GL_SELECT);
    glInitNames();

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, (GLint*) &viewport);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(x,y, 2, 2, (GLint*) &viewport);
    gluPerspective(fovy, (GLfloat) width/height, 0.01, 100.0);
    glMatrixMode(GL_MODELVIEW);
    
    glPushName(0);

    //draw the scene we will select from
    if (f)
      drawQuads(f);
    else
      drawHDS(true);
      

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    const GLuint hitlist = glRenderMode(GL_RENDER);
    return processHits(hitlist, buffer);
}
void pickRects(AUX_EVENTREC *event)
{
    GLuint selectBuf[BUFSIZE];
    GLint hits;
    GLint viewport[4];
    int x, y;

    x = event->data[AUX_MOUSEX];
    y = event->data[AUX_MOUSEY];
    glGetIntegerv (GL_VIEWPORT, viewport);

    glSelectBuffer (BUFSIZE, selectBuf);
    (void) glRenderMode (GL_SELECT);

    glInitNames();
    glPushName(-1);

    glMatrixMode (GL_PROJECTION);
    glPushMatrix ();
    glLoadIdentity ();
/*  create 5x5 pixel picking region near cursor location	*/
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 
	5.0, 5.0, viewport);
    glOrtho (0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
    drawRects (GL_SELECT);
    glPopMatrix ();
    glFlush ();

    hits = glRenderMode (GL_RENDER);
    processHits (hits, selectBuf);
} 
void selectionDetection(int button, int state, int x, int y)
{
    GLuint selectBuf[ BUFSIZE ] ;
    GLint viewport[4];
    if (state !=GLUT_DOWN)
        return;
    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(BUFSIZE, selectBuf);
    (void) glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
    gluPerspective(45.0, (GLfloat) ww/(GLfloat) wh, 1.0, 50.0);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    draw(GL_SELECT);
    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();
    glMatrixMode(GL_MODELVIEW);
    processHits( glRenderMode(GL_RENDER),selectBuf, button);
}
Beispiel #18
0
Vector<int> GLCtrl::GLPicking::Pick(int x, int y, Callback resizeCallback, Callback paintCallback) 
{
	GLuint buffer[_bufferSize];
	
	_pickPoint = Point(x, y);
	
	glSelectBuffer(_bufferSize, buffer);
	glRenderMode(GL_SELECT);
	
	_isPicking = true;
	resizeCallback();
	
	glInitNames();
	paintCallback();
	
	_isPicking = false;
	resizeCallback();
	
	// returning to normal rendering mode
	int hits = glRenderMode(GL_RENDER);
	
	if (hits == 0)
		return Vector<int>();
	else 
		return ParseHits(buffer, hits);
}
Beispiel #19
0
/// returns the selected face, NULL if nothing selected
view::face* view::get_selected_face(int x, int y) {
	GLuint select_buf[SELECT_BUF_SIZE];
	glSelectBuffer(SELECT_BUF_SIZE, select_buf);
	glRenderMode(GL_SELECT);
	glInitNames();
	GLdouble projection_matrix[16];
	glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);
	gluPickMatrix (GLdouble(x), GLdouble(viewport[3] - y), SELECT_TOL, SELECT_TOL, viewport);
	glMultMatrixd(projection_matrix);
	basemesh_drawable->render_faces();
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixd(projection_matrix);
	glFlush();
	GLint hits = glRenderMode(GL_RENDER);
	if (hits > 0) {
		int selected_face = select_buf[3];
		int depth = select_buf[1];
		for (int i = 1; i < hits; i++) {
			if (select_buf[i*4+1] < GLuint(depth))  {
				selected_face = select_buf[i*4+3];
				depth = select_buf[i*4+1];
			}
		}
		return (face*)selected_face;
	}
	return NULL;
}
Beispiel #20
0
int
__glXDisp_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
{
    __GLXcontext *cx;
    GLsizei size;
    int error;

    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
    if (!cx) {
        return error;
    }

    pc += __GLX_SINGLE_HDR_SIZE;
    size = *(GLsizei *) (pc + 0);
    if (cx->selectBufSize < size) {
        cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
                                           (size_t) size * __GLX_SIZE_CARD32);
        if (!cx->selectBuf) {
            cl->client->errorValue = size;
            return BadAlloc;
        }
        cx->selectBufSize = size;
    }
    glSelectBuffer(size, cx->selectBuf);
    cx->hasUnflushedCommands = GL_TRUE;
    return Success;
}
Beispiel #21
0
void 
pickRects(int button, int state, int x, int y)
{
  GLuint selectBuf[BUFSIZE];
  GLint hits;
  GLint viewport[4];

  if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)
    return;

  glGetIntegerv(GL_VIEWPORT, viewport);

  glSelectBuffer(BUFSIZE, selectBuf);
  (void) glRenderMode(GL_SELECT);

  glInitNames();
  glPushName((GLuint) ~0);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
/*  create 5x5 pixel picking region near cursor location */
  gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),
    5.0, 5.0, viewport);
  glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
  drawRects(GL_SELECT);
  glPopMatrix();
  glFlush();

  hits = glRenderMode(GL_RENDER);
  processHits(hits, selectBuf);
}
Beispiel #22
0
void mouse(int button, int state, int x, int y)
{
   GLuint selectBuf[SIZE];
   GLint hits;
   GLint viewport[4];
   if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
   {
   glGetIntegerv (GL_VIEWPORT, viewport);
   glSelectBuffer (SIZE, selectBuf);
   glRenderMode(GL_SELECT);
   glInitNames();
   glPushName(0);
   glMatrixMode (GL_PROJECTION);
   glPushMatrix ();
   glLoadIdentity ();
/*  create 5x5 pixel picking region near cursor location */
   gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
                  5.0, 5.0, viewport);
   gluOrtho2D (-2.0, 2.0, -2.0, 2.0);
   drawObjects(GL_SELECT);
   glMatrixMode (GL_PROJECTION);
   glPopMatrix ();
   glFlush ();
   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
   glutPostRedisplay();
   }
}
static GLint
DoSelect(GLint x, GLint y)
{
  GLint hits;

  glSelectBuffer(MAXSELECT, selectBuf);
  glRenderMode(GL_SELECT);
  glInitNames();
  glPushName(~0);

  glPushMatrix();

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPickMatrix(x, windH - y, 4, 4, vp);
  gluOrtho2D(-175, 175, -175, 175);
  glMatrixMode(GL_MODELVIEW);

  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);

  glScalef(zoom, zoom, zoom);
  glRotatef(zRotation, 0, 0, 1);

  Render(GL_SELECT);

  glPopMatrix();

  hits = glRenderMode(GL_RENDER);
  if (hits <= 0) {
    return -1;
  }
  return selectBuf[(hits - 1) * 4 + 3];
}
Beispiel #24
0
int
__glXDispSwap_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
{
    ClientPtr client = cl->client;
    __GLXcontext *cx;
    GLsizei size;

    __GLX_DECLARE_SWAP_VARIABLES;
    int error;

    REQUEST_FIXED_SIZE(xGLXSingleReq, 4);

    __GLX_SWAP_INT(&((xGLXSingleReq *) pc)->contextTag);
    cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
    if (!cx) {
        return error;
    }

    pc += __GLX_SINGLE_HDR_SIZE;
    __GLX_SWAP_INT(pc + 0);
    size = *(GLsizei *) (pc + 0);
    if (cx->selectBufSize < size) {
        cx->selectBuf = reallocarray(cx->selectBuf,
                                     (size_t) size, __GLX_SIZE_CARD32);
        if (!cx->selectBuf) {
            cl->client->errorValue = size;
            return BadAlloc;
        }
        cx->selectBufSize = size;
    }
    glSelectBuffer(size, cx->selectBuf);
    return Success;
}
Beispiel #25
0
void igvInterfaz::inicia_seleccion(int TAMANO_LISTA_IMPACTOS, GLuint *lista_impactos) {
	glSelectBuffer(TAMANO_LISTA_IMPACTOS, lista_impactos);

	glRenderMode(GL_SELECT);

	interfaz.camara.establecerSeleccion(1, 1, interfaz.ancho_ventana/2, interfaz.alto_ventana/2);
}
Beispiel #26
0
point mouse_pointer::draw_grid()
{
    GLint x;
    GLint y;
    GLint block;
    GLint hits;
    
    // Set up a selection buffer
    GLuint buffer[512];
    gl_vector3 v1;
    gl_vector3 v2;
    gl_vector3 v3;
    gl_vector3 v4;
    point cell;

    ini_manager ini_mgr;
    GLint pt_size = ini_mgr.get_int("Pointer Settings", "pt_size");

    memset(buffer, 0, sizeof(buffer));

    // Tell OpenGL to use our array for selection
    glSelectBuffer(512, buffer);

    // Put OpenGL in selection mode.
    glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
    block = 0;
    glDisable(GL_CULL_FACE);

    for(y = 0; y < map_->get_size(); y += pt_size) {
        for(x = 0; x < map_->get_size(); x += pt_size) {
            block = x + (y * map_->get_size());
            glLoadName(block);
            v1 = map_->get_position(x, y);
            v2 = map_->get_position(x, y + pt_size);
            v3 = map_->get_position(x + pt_size, y + pt_size);
            v4 = map_->get_position(x + pt_size, y);

            glBegin(GL_QUADS);
            glVertex3fv(v1.get_data());
            glVertex3fv(v2.get_data());
            glVertex3fv(v3.get_data());
            glVertex3fv(v4.get_data());
            glEnd();
        }
    }

    hits = glRenderMode(GL_RENDER);
    cell.set_y(-1);
    cell.set_x(-1);

    if(hits > 0) {
        block = buffer[3];
        cell.set_x((block % map_->get_size()) + (pt_size / 2));
        cell.set_y(((block - cell.get_x()) / map_->get_size()) + (pt_size / 2));
    }

    return cell;
}
Beispiel #27
0
int GLWidget::faceAtPosition(const QPoint &pos)
{
    const int MaxSize = 512;
    GLuint buffer[MaxSize];
    GLint viewport[4];

    makeCurrent();

    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(MaxSize, buffer);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(0);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    //gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()), 5.0, 5.0, viewport);
    GLfloat x = GLfloat(width()) / height();
    glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    if (!glRenderMode(GL_RENDER))
        return -1;
    return buffer[3];
}
Beispiel #28
0
static void selectObjects(void)
{
   GLuint selectBuf[BUFSIZE];
   GLint hits;

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glPushMatrix ();
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glOrtho (0.0, 5.0, 0.0, 5.0, 0.0, 10.0);
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ();
   glLoadName(1);
   drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0);
   glLoadName(2);
   drawTriangle (2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0);
   glLoadName(3);
   drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0);
   drawTriangle (2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
} 
/******************************************************
   Handle mouse events
*******************************************************/
void HandleMouse(int button,int state,int x,int y)
{
   int i,maxselect = 100,nhits = 0;
   GLuint selectlist[100];

   if (state == GLUT_DOWN) {
      glSelectBuffer(maxselect,selectlist);
      glRenderMode(GL_SELECT);
      glInitNames();
      glPushName(-1);

      glPushMatrix();
      MakeCamera(TRUE,x,y);
      MakeGeometry();
      glPopMatrix();
      nhits = glRenderMode(GL_RENDER);

      if (button == GLUT_LEFT_BUTTON) {

      } else if (button == GLUT_MIDDLE_BUTTON) {

      } /* Right button events are passed to menu handlers */

      if (nhits == -1)
         fprintf(stderr,"Select buffer overflow\n");

      if (nhits > 0) {
         fprintf(stderr,"\tPicked %d objects: ",nhits);
         for (i=0;i<nhits;i++)
            fprintf(stderr,"%d ",selectlist[4*i+3]);
         fprintf(stderr,"\n");
      }

   }
}
Beispiel #30
0
void gl_selectbuffer( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) {

  // Retrieve memory ptr from double argument:
  GLuint* ptr = (GLuint*) PsychDoubleToPtr((GLdouble) mxGetScalar(prhs[1]));

  if (NULL == glSelectBuffer) mogl_glunsupported("glSelectBuffer");
  glSelectBuffer((GLsizei)mxGetScalar(prhs[0]), ptr);
}