tylerdurden83
04-10-2005, 10:10
Ragazzi ho dei problemi con questo programma qui sotto. Finalmente ho capito come caricare le texture, ma di probl ce ne sn ancora molti, e sono:
1) il quadrato con la texture o non viene visualizzato o copre i puntini (io lo vorrei dietro di essi)
2) i punti e le linee appaiono tutti allo stesso tempo, mentre vorrei che compaiano prima un punto alla volta, e poi una linea alla volta...
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include "geometry2d.h"
#include "tga.h"
#define NUMBER_OF_POINTS 300
#define MIN_X 0.0
#define MAX_X 100.0
#define MIN_Y 0.0
#define MAX_Y 100.0
int width, height;
Point2D *points[(int)NUMBER_OF_POINTS];
int debug = FALSE;
int alive[(int)NUMBER_OF_POINTS];
Point2D *minX, *maxX;
int indiceMinX, indiceMaxX;
double colore;
void myreshape(int w, int h);
void drawFace (void)
{
glEnable (GL_TEXTURE_2D); /* enable texture mapping */
glBindTexture (GL_TEXTURE_2D, 1); /* bind to our texture, has id of 13 */
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f); // lower left corner of image
glVertex3f (-10.0f, -10.0f, -1.0f);
glTexCoord2f (1.0f, 0.0f); // lower right corner of image
glVertex3f (100.0f, -10.0f, -1.0f);
glTexCoord2f (1.0f, 1.0f); // upper right corner of image
glVertex3f (100.0f, 100.0f, -1.0f);
glTexCoord2f (0.0f, 1.0f); // upper left corner of image
glVertex3f (-10.0f, 100.0f, -1.0f);
glEnd ();
glDisable (GL_TEXTURE_2D); /* disable texture mapping */
}
int init()
{
minX = NULL;
maxX = NULL;
glClearColor (0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 1.0);
colore=0.0;
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10.0, MAX_X+MAX_X/10,-10.0, MAX_Y+MAX_Y/10);
myreshape(width, height);
int i;
for(i = 0; i < NUMBER_OF_POINTS; i++)
{
points[i] = random2DPoint(MIN_X, MAX_X, MIN_Y, MAX_Y);
if(minX == NULL || minX->x > points[i]->x) {
minX = points[i];
indiceMinX = i;
}
if(maxX == NULL || maxX->x < points[i]->x) {
maxX = points[i];
indiceMaxX = i;
}
}
if (!loadTGA ("256.tga", 1))
printf ("texture not found!\n");
}
void convexRecursion(Point2D *estremoA, Point2D *estremoB, Point2D *puntoInSemipianoErrato)
{
....
}
void mydisplay()
{
int i;
for(i = 0; i < NUMBER_OF_POINTS; i++) {
alive[i] = TRUE;
}
alive[indiceMinX] = FALSE;
alive[indiceMaxX] = FALSE;
// clear window
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_POINT_SMOOTH);
glPointSize(4.0);
glColor3f(1.0, 0.58, 0.1);
glBegin(GL_POINTS);
for(i = 0; i < NUMBER_OF_POINTS; i++) {
glVertex2f(points[i]->x, points[i]->y);
}
glEnd();
Point2D *p = (Point2D *)malloc(sizeof(Point2D));
p->x = minX->x;
p->y = minX->y+5;
convexRecursion(minX, maxX, p);
p->x = minX->x;
p->y = minX->y-5;
convexRecursion(minX, maxX, p);
free(p);
drawFace ();
// flush GL buffers
glFlush();
}
void myreshape(int w, int h)
{
width = w;
height = h;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); // switch matrix mode
glLoadIdentity();
GLdouble ratio;
if (width <= height) {
ratio = (GLfloat) height / (GLfloat) width;
gluOrtho2D(-10.0, MAX_X+MAX_X/10,-10.0*ratio, (MAX_Y+MAX_Y/10)*ratio);
} else {
ratio = (GLfloat) width / (GLfloat) height;
gluOrtho2D(-10.0*ratio, (MAX_X+MAX_X/10)*ratio,-10.0, MAX_Y+MAX_Y/10);
}
glMatrixMode(GL_MODELVIEW); // return to modelview mode
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
height = 640;
width = 480;
glutInitWindowPosition(175,120);
glutCreateWindow("convexHull");
glutDisplayFunc(mydisplay);
glutReshapeFunc(myreshape);
init();
glutMainLoop();
}
1) il quadrato con la texture o non viene visualizzato o copre i puntini (io lo vorrei dietro di essi)
2) i punti e le linee appaiono tutti allo stesso tempo, mentre vorrei che compaiano prima un punto alla volta, e poi una linea alla volta...
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include "geometry2d.h"
#include "tga.h"
#define NUMBER_OF_POINTS 300
#define MIN_X 0.0
#define MAX_X 100.0
#define MIN_Y 0.0
#define MAX_Y 100.0
int width, height;
Point2D *points[(int)NUMBER_OF_POINTS];
int debug = FALSE;
int alive[(int)NUMBER_OF_POINTS];
Point2D *minX, *maxX;
int indiceMinX, indiceMaxX;
double colore;
void myreshape(int w, int h);
void drawFace (void)
{
glEnable (GL_TEXTURE_2D); /* enable texture mapping */
glBindTexture (GL_TEXTURE_2D, 1); /* bind to our texture, has id of 13 */
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f); // lower left corner of image
glVertex3f (-10.0f, -10.0f, -1.0f);
glTexCoord2f (1.0f, 0.0f); // lower right corner of image
glVertex3f (100.0f, -10.0f, -1.0f);
glTexCoord2f (1.0f, 1.0f); // upper right corner of image
glVertex3f (100.0f, 100.0f, -1.0f);
glTexCoord2f (0.0f, 1.0f); // upper left corner of image
glVertex3f (-10.0f, 100.0f, -1.0f);
glEnd ();
glDisable (GL_TEXTURE_2D); /* disable texture mapping */
}
int init()
{
minX = NULL;
maxX = NULL;
glClearColor (0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 1.0);
colore=0.0;
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10.0, MAX_X+MAX_X/10,-10.0, MAX_Y+MAX_Y/10);
myreshape(width, height);
int i;
for(i = 0; i < NUMBER_OF_POINTS; i++)
{
points[i] = random2DPoint(MIN_X, MAX_X, MIN_Y, MAX_Y);
if(minX == NULL || minX->x > points[i]->x) {
minX = points[i];
indiceMinX = i;
}
if(maxX == NULL || maxX->x < points[i]->x) {
maxX = points[i];
indiceMaxX = i;
}
}
if (!loadTGA ("256.tga", 1))
printf ("texture not found!\n");
}
void convexRecursion(Point2D *estremoA, Point2D *estremoB, Point2D *puntoInSemipianoErrato)
{
....
}
void mydisplay()
{
int i;
for(i = 0; i < NUMBER_OF_POINTS; i++) {
alive[i] = TRUE;
}
alive[indiceMinX] = FALSE;
alive[indiceMaxX] = FALSE;
// clear window
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_POINT_SMOOTH);
glPointSize(4.0);
glColor3f(1.0, 0.58, 0.1);
glBegin(GL_POINTS);
for(i = 0; i < NUMBER_OF_POINTS; i++) {
glVertex2f(points[i]->x, points[i]->y);
}
glEnd();
Point2D *p = (Point2D *)malloc(sizeof(Point2D));
p->x = minX->x;
p->y = minX->y+5;
convexRecursion(minX, maxX, p);
p->x = minX->x;
p->y = minX->y-5;
convexRecursion(minX, maxX, p);
free(p);
drawFace ();
// flush GL buffers
glFlush();
}
void myreshape(int w, int h)
{
width = w;
height = h;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); // switch matrix mode
glLoadIdentity();
GLdouble ratio;
if (width <= height) {
ratio = (GLfloat) height / (GLfloat) width;
gluOrtho2D(-10.0, MAX_X+MAX_X/10,-10.0*ratio, (MAX_Y+MAX_Y/10)*ratio);
} else {
ratio = (GLfloat) width / (GLfloat) height;
gluOrtho2D(-10.0*ratio, (MAX_X+MAX_X/10)*ratio,-10.0, MAX_Y+MAX_Y/10);
}
glMatrixMode(GL_MODELVIEW); // return to modelview mode
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
height = 640;
width = 480;
glutInitWindowPosition(175,120);
glutCreateWindow("convexHull");
glutDisplayFunc(mydisplay);
glutReshapeFunc(myreshape);
init();
glutMainLoop();
}