Note that there are some explanatory texts on larger screens.

plurals
  1. POOpengl+c++ Need to render a multicolored square but my code is showing blank screen
    primarykey
    data
    text
    <p>I am learning Opengl in c++ I am trying to render a multi color square but first I want to show up a simple square. But all in vain it is showing a blank screen. I am trying it on xcode my code is </p> <pre><code>#include &lt;iostream&gt; #include &lt;GLUT/GLUT.h&gt; #include&lt;OpenGL/OpenGL.h&gt; void init(void) { glShadeModel( GL_SMOOTH ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); glEnable( GL_COLOR_MATERIAL ); glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } void coloredSquare(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin ( GL_LINES ); glColor3f ( 0.9,0.9,0.9 ); // very light gray for(int i=10;i&lt;180;i+=10) // vertical lines { glVertex2f( i,0 ); glVertex2f( i,180 ); } for(int j=10;j&lt;180;j+=10) // horizontal lines { glVertex2f( 0,j ); glVertex2f( 180,j ); } glEnd(); // b. points glPointSize(3.0); // 3 pixel point. why it only works outside of glBegin-glEnd. glBegin ( GL_POINTS ); glColor3f ( 0.3,0.3,0.3 ); // dark gray for(int i=10;i&lt;180;i+=10) // draw point at every grid intersection { for(int j=10;j&lt;180;j+=10) { glVertex2f( i,j ); } } glEnd(); glFlush(); // Render now } int main(int argc, char** argv) { //GLUT &amp; OpenGL glutInit(&amp;argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(200, 200); //glutInitWindowPosition(0, 0); glutCreateWindow("GLUT Program"); //glutCreateWindow("Colored Square"); init(); glutDisplayFunc(coloredSquare); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } </code></pre> <p>If some body has some idea please do throw some light on this thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload