Jump to content
  • Advertisement
Sign in to follow this  
FeralShadow

Picking problem no hits detected

This topic is 3817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, We're trying to get picking to work with fltk.. but sadly enough it doesn´t seem to work. We've tried diffrent tutorials and some samples (which do work) but still we're doing something wrong. When we call glRenderMode(GL_RENDER) it returns 0 and it remains 0, right now we have the code stated below. hopefully someone can help us.
#include "Renderer.h"

#include <stdio.h>
#include <stdlib.h>

Renderer::Renderer(int x, int y, int width, int height) : Fl_Gl_Window(x, y, width, height) {
	Fl::add_idle(idle, this);
}

void Renderer::draw() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (!valid()) {
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
	      	glEnable(GL_DEPTH_TEST);
       		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_NORMALIZE);
	}

	drawClear();		
	drawSetupTransform();

	float ratio = w() / h();
	glFrustum(-0.1f * ratio, 0.1f * ratio, -0.1f, 0.1f, 0.2f, 100.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0, 0, 0, 10, 10, 10, 0, 1, 0);

	glTranslatef(20,20,20);
	drawObjects();
}

void Renderer::drawClear() {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT);
}

void Renderer::drawObjects() {
	glLoadName(7);
	glBegin(GL_LINES);
		glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(0.0f, 0.0f, 0.0f);
			glVertex3f(5.0f, 0.0f, 0.0f);
		glColor3f(0.0f, 1.0f, 0.0f);
			glVertex3f( 0.0f, 0.0f, 0.0f);
			glVertex3f( 0.0f, 5.0f, 0.0f);
		glColor3f(0.0f, 0.0f, 1.0f);
			glVertex3f(0.0f, 0.0f, 0.0f);
			glVertex3f(0.0f, 0.0f, 5.0f);
	glEnd();
}

void Renderer::drawSetupTransform() {
	glOrtho(-1,1,-1,1,-1,1);
}


int Renderer::handle(int event) {
	switch (event) {
		case FL_FOCUS:
			break;
		case FL_UNFOCUS:
			event = 1;
			break;
		case FL_PUSH:
			pick(Fl::event_x(), Fl::event_y());
			break;
	}

	return Fl_Gl_Window::handle(event);
}

void Renderer::idle(void* data) {
	Renderer* window = (Renderer*)data;
	window->redraw();
}

void Renderer::pick(int x, int y) {
	//0,0 in GL leftunder, WINDOW is 0,0 uperleft
	y = 600 -y;

	make_current();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	int viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);

	gluPickMatrix(x,viewport[3]-y,5,5,viewport);
	drawSetupTransform();

	GLuint buf[100];
	glSelectBuffer(100,buf);
	glRenderMode(GL_SELECT);
	glInitNames();
	glPushName(0);

	drawObjects();
	int hits = glRenderMode(GL_RENDER);
	printf("number of hits %d\n", hits);
}
 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!