PDA

View Full Version : Not rendering



iris_raj
11-10-2003, 02:27 AM
The following is the code for drawing a vertex data
from a external. I have the following code.It is reading data from the file. But nothing is being rendered on the screen.kindly tell me what is problem

#include <stdio.h>
#include <GL/glut.h>
#include <GL/gl.h>

float a[24];
void fileread();

void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
fileread();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0f,0.0f,1.0f);

glTranslatef(0.0,0.0,4.0f);
glBegin(GL_POINTS);
glVertex3fv(a);
glEnd();
glFlush();
}
void reshape(int w,int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-3.5, 3.5, -3.5*(GLfloat)h/(GLfloat)w,
3.5*(GLfloat)h/(GLfloat)w, -3.5, 3.5);
else
glOrtho (-3.5*(GLfloat)w/(GLfloat)h,
3.5*(GLfloat)w/(GLfloat)h, -3.5, 3.5, -3.5, 3.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void fileread()
{
int i,j;
FILE *fp;
fp = fopen("test.dat","r");
for(i=0;i<24;i++)
{
fscanf(fp,"%f",&a[i]);
}
for(i=0;i<24;i++)
{
printf("a[%d] = %f\n",i,a[i]);
}
}
int main(int argc, char*argv[])
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(512,512);
glutInitWindowPosition(50,50);
glutInit(&argc, argv);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

With regards
RAJESH.R

Andrea Rossini
11-10-2003, 03:01 AM
You need:
1- a pixel format
2- at least 1 rendering context
3- a current rendering context

on MSDN search for
SetPixelFormat
wglCreateContext
wglMakeCurrent

take a look at these lessons too: http://nehe.gamedev.net

Andrea Rossini
11-10-2003, 03:03 AM
Oooops, sorry I did not see you are using glut/glaux, I never use them so I've no clue about that

11-10-2003, 03:07 AM
glBegin(GL_POINTS);
glVertex3fv(a);
glEnd();

it's only reading one point.

glBegin(GL_POINTS);
glVertex3fv(&a[0]);
glVertex3fv(&a[3]);
... up to
glVertex3fv(&a[21]);
glEnd();

ought to work

11-10-2003, 03:11 AM
also... looking at your ortho view values, if your points are < -3 or > 3, they aren't in view and will be clipped. you may have to adjust these to fit your minimum and maximum points.