OpenGL, GLUT, GLEW - window always blank white - c++

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();
}

Related

Glut/OpenGL always renders black window

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?

OpenGL white blank screen and not responding

I am using SDL2.00 with OpenGL to create a program. The program isn't supposed to do anything at the moment it's just a test bed. However I ran into a problem. When I create a window using SDL_CreateWindow, the window goes into a busy state and stops responding. The program flow isn't really affected by this however the window itself just won't work. All it does is show a white blank window and accept no input, can't resize can't move and can't quit. I will attach the code but I doubt it is code related since I already made a few programs using SDL and they seem to work just fine.
Using VS2013 SDL2.00 OpenGL
=========main========
#include "stdafx.h"
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 640.0 / 480.0, 1.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 2.0, -5.0);
glVertex3f(-2.0, -2.0, -5.0);
glVertex3f(2.0, -2.0, -5.0);
glEnd();
}
int main(int argc, char* argv[]){
SDL_Init(SDL_INIT_VIDEO);
SDL_Window * window;
window = SDL_CreateWindow("OpenGLTest", 300, 300, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
init();
while (true){
display();
SDL_GL_SwapWindow(window);
}
return 0;
}
=========stdafx======
#pragma once
#include <iostream>
#include <SDL.h>
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#define PI 3.14159265
using namespace std;
You forgot to process all the events, so the SDL window is just waiting and waiting and waiting, thereby "not responding" - Simply adding that should fix the problem!
while (true) {
SDL_PumpEvents();
display();
SDL_GL_SwapWindow(window);
}
You could also pull all the events manually with a loop calling SDL_PollEvent(SDL_Event *event)
SDL_Event event;
while (SDL_PollEvent(&event)) {
// Process the event...
}
Wiki
SDL_PumpEvents() - http://wiki.libsdl.org/SDL_PumpEvents
SDL_PollEvent() - http://wiki.libsdl.org/SDL_PollEvent

openGL window crash

i am working on openGL in Vc6
every time i run the following simple code output window crashes
#include <stdio.h>
#include <gl/glut.h>
//#include <gl/glaux.h>
void display(void)
{
glColor3f(255.0f,255.0f,255.0f);
glBegin(GL_QUADS);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,5.0f,0.0f);
glVertex3f(5.0f,5.0f,0.0f);
glVertex3f(5.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glEnd();
glFlush();
}
void init(void)
{
glViewport(0,0,400,400);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,4/3,4.0,1000.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(2.0,2.0,2.0,1.0,2.0,1.0,0.0,1.0,0.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
init();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowPosition(400,400);
glutInitWindowSize(400,400);
glutCreateWindow("Trial");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
i don't know what is going wrong any boby please help
You are using OpenGL functions before you have an OpenGL context (which is a requirement to call any GL functions at all). The context is created by glutCreateWindow, but your first call to GL functions happens in init(). To fix this, you could move your init() call right below the glutCreateWindow call.

Error when running OpenGL project under Ubuntu 10.10

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 ();
}

Why don't any of the integer methods work for OpenGL?

I'm developing C++ OpenGL code in Windows using Visual Studio 2008. I can't for the life of me understand why none of the integer functions work. I'll try using glVertex2i(2,2) but all I get is a black screen, I've also tried this with glrecti but I have had the same result.
When I use the floating point functions, they work. glVertex2f(.5,.5) and glRectf(1,2,3,4) work fine. I just can't figure out what is going wrong, what I have missed. People have obviously used glVertex2i before and had it work.
The simple code I've been working off of is this:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
void draw(){
glClearColor(0,0,0,1);
glClear( GL_COLOR_BUFFER_BIT );
glColor3f(1, 1, 1);
glBegin(GL_LINES);
glVertex2i(100,100);
glVertex2i(200,200);
glEnd();
glFlush();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutCreateWindow("My first OpenGL program");
glutDisplayFunc(draw);
glutMainLoop();
}
Your code doesn't set any projection matrices, so passing values outside [-1, 1] is drawing outside of the viewport. That's why integer functions "don't work".