LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   my opengl program gives a blank output screen after compilation... (https://www.linuxquestions.org/questions/linux-newbie-8/my-opengl-program-gives-a-blank-output-screen-after-compilation-865176/)

prayas.suneja 02-26-2011 12:28 PM

my opengl program gives a blank output screen after compilation...
 
i compiled this code and got no error.....but the output screen is blank.


the code is as follows:
-------------------------------------------------------------------------
# include <GL/glut.h>
# include <iostream>
# include <cstdio>
using namespace std;

void init(int w,int h)
{
glClearColor(0,0.5,0.5,0.0);
glMatrixMode(GL_PROJECTION);
glViewport(0,0,w,h);
}

void dispfcn()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2i(50,50);
glVertex2i(100,50);
glVertex2i(75,100);
glEnd();
glFlush();
}

int main(int argc,char**argv)
{
int w,h;
w=h=400;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(w,h);
glutCreateWindow("triangle");
init(w,h);
glutDisplayFunc(dispfcn);
glutMainLoop();
return 0;
}
-------------------------------------------------------------------------

i compiled the program as follows:
g++ first.cpp -o first -lglut

adamk75 02-26-2011 02:12 PM

I get just a gray window here, on two separate machines with different drivers. Where did you get the code? Do you know what it is supposed to produce?

Adam

prayas.suneja 02-26-2011 05:32 PM

i wrote this code...
it is a simple program to draw a triangle.....

i made this program with the help of some programs available on the internet(which worked perfectly fine in my distro) and the program i ran in visual c++(in my college lab),this is a hybrid...i guess there is some logical error or incorrect usage of function that's why blank screen is coming......
its working fine in the main where we can change the background display....but the 'dispfunc' is not displaying the triangle....

adamk75 02-26-2011 05:58 PM

I'd suggest that this isn't the best forum for troubleshooting OpenGL programming errors. This forum will probably get you better results:

http://www.opengl.org/discussion_boards/

Adam


All times are GMT -5. The time now is 09:05 PM.