Lines are black

  • Follow


Sorry for asking so many questions, its just that i am so into this now
a days and i encounter a few problems a day. usually they are pretty
simple problems as you can see, but thanks anyway.

okay so i have the following code....


#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <Math.h>

#define PI 3.1415926535898

float zoom = 12.0f;
double angle;
double a=0.0,b=0.0;

void init(void)
{
     //glShadeModel(GL_SMOOTH);
     //glClearColor (0.0f,0.0f,0.0f,0.5f);
     GLfloat mat_specular[]={1.0,1.0,0.0,1.0};
     GLfloat light_position[]={3.0,4.0,100.0,0.0};
     glClearColor (0.1,0.1,0.1,0.0);
     glShadeModel(GL_SMOOTH);
     glEnable(GL_DEPTH_TEST);
     //glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseMaterial);
     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
     glMaterialf(GL_FRONT, GL_SHININESS, 1000.0);
     glLightfv(GL_LIGHT0, GL_POSITION, light_position);
     glEnable(GL_LIGHTING);
     glEnable(GL_LIGHT0);
     glColorMaterial(GL_FRONT, GL_DIFFUSE);
     glEnable(GL_COLOR_MATERIAL);
}

void glRotatef(
  GLfloat angle,
  GLfloat x,
  GLfloat y,
  GLfloat z
);


void drawString (const char *s)    //How do display text
{
  unsigned int i;
  for (i = 0; i < strlen (s); i++)
    glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, s[i]);

};


void display(void)
{
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     glPushMatrix();
     //glTranslatef(0,0,-zoom);

     glTranslatef(-2,-2,-zoom);
     glColor4f(0.2,0.2,1.0,0.0);
     glutSolidSphere(1.0,200,16);
     glTranslatef(3,4,-zoom);
     glColor3f(0.7,0.7,0.0);
     glutSolidSphere(1.0,200,16);
     glTranslatef(3,4,-zoom);
     glColor3f(1.0,0.0,0.0);
     glutSolidSphere(1.0,200,16);
     glTranslatef(5,9,-20);
     glColor3f(1.0,0.6,0.0);
     glutSolidSphere(10.0,200,16);

     glColor4f(1.0,0.0,0.0,1.0);   //LINE HERE
     glLineWidth(5.0);
     glBegin(GL_LINES);
     glVertex3f(-10000,0,10);
     glVertex3f(100000,0,10);
     glutPostRedisplay();
     glEnd();

     glTranslatef(a,b,-zoom);
     glColor3f(1.0,0.2,0.0);
     glutSolidSphere(1.0,200,16);
     a-=0.3;
     b-=0.3;

     glutFullScreen( );


     glPopMatrix();
     glFlush();
     glLoadIdentity();
     glutSwapBuffers();
     glutPostRedisplay();
}


void reshape( int w, int h)
{
	glViewport(0,0, (GLsizei) w, (GLsizei) h);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     if(w<=h)
     {
             glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w, -10.0,10.0);
     }
     else
     {
             glOrtho(-1.5*(GLfloat)w/(GLfloat)h,
1.5*(GLfloat)w/(GLfloat)h, -1.5,1.5,-10.0,10.0);
     }
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45,(float)w/h,0.1,100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	/*glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45,(float)w/h,0.1,100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();*/
}

void Keyboard(unsigned char key, int x, int y)
{
     switch(key)
     {
                case 27:
                     exit(0);
                     break;
                default:
                     break;
     }
}

int main(int argc, char** argv)
{
      glutInit(&argc,argv);
    	 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
    	 glutInitWindowSize(1275,955);
    	 glutInitWindowPosition(0,0);
    	 glutCreateWindow("Asteroids");
      init();

    	 glutDisplayFunc(display);
    	 glutReshapeFunc(reshape);
    	 glutKeyboardFunc(Keyboard);

    	 glutMainLoop();
      return 0;
}

and the problem is, where i am drawing a VERY LONG straight line. for
some reason its black and i can't figure it out. i can tell there's a
line there, cause its not the same black that the background is, but
its kind of black. Why is that happening if im setting the color to red?

0
Reply lubanfamily (53) 8/29/2005 1:49:29 AM

bballmitch wrote:
> Sorry for asking so many questions, its just that i am so into this now
> a days and i encounter a few problems a day. usually they are pretty
> simple problems as you can see, but thanks anyway.

Lighting affects lines just as much as other primitives, so turn lighting off 
if you want a pure red line:

glDisable(GL_LIGHTING);
glColor4f(1.0,0.0,0.0,1.0);   //LINE HERE
glLineWidth(5.0);
glBegin(GL_LINES);
   glVertex3f(-10000,0,10);
   glVertex3f(100000,0,10);
   glutPostRedisplay();
glEnd();
glEnable(GL_LIGHTING);

Also, glutFullScreen() should only be called onced durring your GL initialization.


Mike

> okay so i have the following code....
> 
> #include <GL/gl.h>
> #include <GL/glu.h>
> #include <GL/glut.h>
> #include <stdlib.h>
> #include <iostream>
> #include <windows.h>
> #include <cstdio>
> #include <cstdlib>
> #include <string.h>
> #include <stdio.h>
> #include <stdarg.h>
> #include <Math.h>
> 
> #define PI 3.1415926535898
> 
> float zoom = 12.0f;
> double angle;
> double a=0.0,b=0.0;
> 
> void init(void)
> {
>      //glShadeModel(GL_SMOOTH);
>      //glClearColor (0.0f,0.0f,0.0f,0.5f);
>      GLfloat mat_specular[]={1.0,1.0,0.0,1.0};
>      GLfloat light_position[]={3.0,4.0,100.0,0.0};
>      glClearColor (0.1,0.1,0.1,0.0);
>      glShadeModel(GL_SMOOTH);
>      glEnable(GL_DEPTH_TEST);
>      //glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseMaterial);
>      glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
>      glMaterialf(GL_FRONT, GL_SHININESS, 1000.0);
>      glLightfv(GL_LIGHT0, GL_POSITION, light_position);
>      glEnable(GL_LIGHTING);
>      glEnable(GL_LIGHT0);
>      glColorMaterial(GL_FRONT, GL_DIFFUSE);
>      glEnable(GL_COLOR_MATERIAL);
> }
> 
> void glRotatef(
>   GLfloat angle,
>   GLfloat x,
>   GLfloat y,
>   GLfloat z
> );
>
> void drawString (const char *s)    //How do display text
> {
>   unsigned int i;
>   for (i = 0; i < strlen (s); i++)
>     glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, s[i]);
> 
> };
> 
> 
> void display(void)
> {
>      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
>      glPushMatrix();
>      //glTranslatef(0,0,-zoom);
> 
>      glTranslatef(-2,-2,-zoom);
>      glColor4f(0.2,0.2,1.0,0.0);
>      glutSolidSphere(1.0,200,16);
>      glTranslatef(3,4,-zoom);
>      glColor3f(0.7,0.7,0.0);
>      glutSolidSphere(1.0,200,16);
>      glTranslatef(3,4,-zoom);
>      glColor3f(1.0,0.0,0.0);
>      glutSolidSphere(1.0,200,16);
>      glTranslatef(5,9,-20);
>      glColor3f(1.0,0.6,0.0);
>      glutSolidSphere(10.0,200,16);
> 
>      glColor4f(1.0,0.0,0.0,1.0);   //LINE HERE
>      glLineWidth(5.0);
>      glBegin(GL_LINES);
>      glVertex3f(-10000,0,10);
>      glVertex3f(100000,0,10);
>      glutPostRedisplay();

glutPostRedisplay() in the middle of a drawing operation?  Or maybe that's just 
for debugging?  Still, GL won't like that.

>      glEnd();
> 
>      glTranslatef(a,b,-zoom);
>      glColor3f(1.0,0.2,0.0);
>      glutSolidSphere(1.0,200,16);
>      a-=0.3;
>      b-=0.3;
> 
>      glutFullScreen( );
 >
>      glPopMatrix();
>      glFlush();
>      glLoadIdentity();
>      glutSwapBuffers();
>      glutPostRedisplay();
> }
> 
> 
> void reshape( int w, int h)
> {
> 	glViewport(0,0, (GLsizei) w, (GLsizei) h);
>      glMatrixMode(GL_PROJECTION);
>      glLoadIdentity();
>      if(w<=h)
>      {
>              glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,
> 1.5*(GLfloat)h/(GLfloat)w, -10.0,10.0);
>      }
>      else
>      {
>              glOrtho(-1.5*(GLfloat)w/(GLfloat)h,
> 1.5*(GLfloat)w/(GLfloat)h, -1.5,1.5,-10.0,10.0);
>      }
>      glMatrixMode(GL_MODELVIEW);
>      glLoadIdentity();
>      glMatrixMode(GL_PROJECTION);
> 	glLoadIdentity();
> 	gluPerspective(45,(float)w/h,0.1,100);
> 	glMatrixMode(GL_MODELVIEW);
> 	glLoadIdentity();
> 	/*glMatrixMode(GL_PROJECTION);
> 	glLoadIdentity();
> 	gluPerspective(45,(float)w/h,0.1,100);
> 	glMatrixMode(GL_MODELVIEW);
> 	glLoadIdentity();*/
> }
> 
> void Keyboard(unsigned char key, int x, int y)
> {
>      switch(key)
>      {
>                 case 27:
>                      exit(0);
>                      break;
>                 default:
>                      break;
>      }
> }
> 
> int main(int argc, char** argv)
> {
>       glutInit(&argc,argv);
>     	 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
>     	 glutInitWindowSize(1275,955);
 >
>     	 glutInitWindowPosition(0,0);
>     	 glutCreateWindow("Asteroids");
>       init();
> 
>     	 glutDisplayFunc(display);
>     	 glutReshapeFunc(reshape);
>     	 glutKeyboardFunc(Keyboard);
> 
>     	 glutMainLoop();
>       return 0;
> }
> 
> and the problem is, where i am drawing a VERY LONG straight line. for
> some reason its black and i can't figure it out. i can tell there's a
> line there, cause its not the same black that the background is, but
> its kind of black. Why is that happening if im setting the color to red?
0
Reply Mike 8/29/2005 2:19:03 AM


thanks for tips.  and it worked.

0
Reply bballmitch 8/29/2005 2:25:32 AM

2 Replies
80 Views

(page loaded in 0.059 seconds)

Similiar Articles:













7/18/2012 8:55:39 PM


Reply: