I had OpenGL project for finding a convex hull written in Windows.
Now i'm using Ubuntu 10.10 and i tried to port the code (It's C++ code) and run it.
I saw that, it should be compiled this way :
g++ convex.cpp -lm -lglut -lGLU -o convex_hull_project
It compiles the file, but when i run the file ./convex_hull_project it starts the program, shows the title but there is nothing - it only docks for the bottom task line and when i click it - nothing shows. There is no window with the program.
Any idea ?
Here's the code that uses OpenGL stuff :
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
glutInitWindowPosition(100,100);
glutInitWindowSize(window_size_width,window_size_height);
glutCreateWindow("Convex hull");
glutDisplayFunc(renderScene);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
void renderScene(void) {
// clear framebuffer
glClearColor(0.f,0.f,0.f,0.f);
glClear(GL_COLOR_BUFFER_BIT);
// set-up matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,window_size_width,window_size_height,0,-1,1);
glViewport(0,0,window_size_width,window_size_height);
//drawing ...
}
And includes are :
#include<GL/glut.h>
#include<GL/glu.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
You have to call glutCreateWindow before you set windows's properties. Your code, fixed (I've replaced width and height constants with 300 just to get it to compile and commented out mouse handler registration):
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <GL/glut.h>
#include <GL/glu.h>
void renderScene(void) {
// clear framebuffer
glClearColor (0.f,0.f,0.f,0.f);
glClear (GL_COLOR_BUFFER_BIT);
// set-up matrix
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, 300, 300, 0,-1,1);
glViewport (0,0,300, 300);
//drawing ...
}
int main(int argc, char* argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
glutCreateWindow ("Convex hull");
glutInitWindowPosition (100, 100);
glutInitWindowSize (300, 300);
glutDisplayFunc (renderScene);
//glutMouseFunc (mouse);
glutMainLoop ();
}
Related
I am changing the window background color using the Glut library, which isn't working. The code works perfectly on my peer's computers but not on mine. I am using Visual Studio on Windows 10, with intel i5,8th gen, with integrated graphics.
I searched on Reddit threads, and the only thing relevant was that integrated graphics may be the issue.
Is integrated graphics really the issue or something else?
Are there any solutions to this problem, except changing the graphic cards?
Note- The library should be OpenGL, glut, glu only...
Code:
#include <GL/glut.h>
#include <gl/GLU.h>
#include <iostream>
using namespace std;
void draw() {}
void display() {
glClearColor(1.0, 1.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
gluOrtho2D(0, 640, 0, 480);
// draw();
glFlush();
return;
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(200, 200);
glutInitWindowSize(640, 480);
glutCreateWindow("House");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
I tried this code, and although it renders a window, it is black in color, which it should not be. It should be (as the question) any random color. Are there any solutions i can try?
The background color of my scene is black. How can I change this color?
Looks like I'm doing something wrong because glClearColor() function is not working: I tried to change the values but nothing happened. I'm new to OpenGL and programming in general.
#include <GL/glut.h>
void Ayarlar(void);
void CizimFonksiyonu(void);
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(200, 200);
glutInitWindowSize(400, 400);
glutCreateWindow("ilk OpenGL programim");
glutDisplayFunc(CizimFonksiyonu);
glutMainLoop();
Ayarlar();
return 0;
}
void Ayarlar(void) {
glClearColor(1 ,0 ,0 , 1);
glShadeModel(GLU_FLAT);
}
void CizimFonksiyonu(void) {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
Ayarlar() has to be called be for glutMainLoop(). glutMainLoop enters the GLUT event processing loop and never returns. You have to set the OpenGL states before.
glutDisplayFunc(CizimFonksiyonu);
Ayarlar();
glutMainLoop();
I am using Dell XPS 9550, x64 Windows 10. with graphics card GeForce GTX 960M. using Visual Studio 2017 C++
OpenGL using GLUT and GLEW does not work while things work fine with GLFW.
I've been using OpenGL for a while, so I am pretty sure I linked header files, libs and dll correctly.
Also, I tested exactly the same project in other computer, and worked fine without any problem.
So I was wondering maybe there exist some compatibility issues with the graphic card? Anyone have any idea?
It should render like this (Desktop Windows 10 x64, GTX 1050):
But on Dell XPS 9550 (GeForce GTX 960M), blank window shows up:
The code I used is:
#include <Windows.h>
#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>
#include <glm/glm.hpp>
#include <gl/glut.h>
#include <gl/gl.h>
#define WINDOW_WIDTH 320
#define WINDOW_HEIGHT 240
void display();
void init();
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow("Main Window");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void init()
{
glClearColor(1, 0, 0, 0);
glDisable(GL_DEPTH_TEST);
// next four lines are new
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, WINDOW_WIDTH - 1, WINDOW_HEIGHT - 1, 0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3ub(255, 255, 255);
glVertex2f(10, 10);
glVertex2f(100, 10);
glVertex2f(100, 100);
glVertex2f(10, 100);
glEnd();
glutSwapBuffers();
}
I just started trying out OpenGL and I'm having a strange issue.
If I compile and execute using g++ test.c -lGL -lGLU -lglut then ./a.out, a sepearate window opens (of the size specified in the code). But instead of having the output of the code in it, it has a screenshot of the screen inside it (of the portion of the screen it overlaps).
This is definitely not something to do with the code, since it's running fine on my friend's computer. But I need to fix it on my PC.
I'm on Linux Mint 15 64bit (HP DV6 6121tx).
So I'm not able to proceed further. Here's my code:
#include <GL/gl.h>
#include <GL/glut.h>
#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D (-600,600,-400,400);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(1200,800);
glutCreateWindow("ABCD");
init();
glutMainLoop();
return 0;
}
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
^^^^^^^^^^^
You've asked for a single-buffered window so you'll have to glFlush()/glFinish() to force queued output to the screen.
Add a glFinish() to the end of init().
I have attempted to start programming with OpenGl using this tutorial, and have the following code so far:
#include <gl/glut.h> // Include the GLUT header file
void display (void)
{
}
int main(int argc, char **argv)
{
glutInit(&argc, argv); // Initialize GLUT
// Set up a basic display buffer (only single buffered for now)
glutInitDisplayMode (GLUT_SINGLE);
glutInitWindowSize (500, 500); // Set the width and height of the window
glutInitWindowPosition (100, 100); // Set the position of the window
// Set the title for the window
glutCreateWindow("Your first OpenGL Window!");
glutDisplayFunc(display);
glutMainLoop();
glClearColor(1.f, 0.f, 0.f, 1.f); // Clear the background of our window to red
return 0;
}
I build and run the project in Eclipse, it compiles all fine, but nothing happens (no windows pop up or anything). Can anybody tell me what I could be doing wrong?
glutInitDisplayMode (GLUT_SINGLE);
You also need to define the kind of framebuffer format you want, i.e. add a GLUT_RGBA, at least (and you probably also want a depth buffer). And there are only few cases where one not wants a double buffer. So: glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
Then your display function will not be called, unless you add a glutDisplayFunc(display); after glutCreateWindow.
glutMainLoop();
glClearColor(1.f, 0.f, 0.f, 1.f);
glutMainLoop does not return. And even if it did, glClearColor had no effect at that place in the program.