PDA

View Full Version : Still getting blank window



Darth_Malloc
08-05-2012, 03:34 PM
The input now works, but the program still gives me a blank window.



void double_cube(GLfloat firstNum, GLboolean buff, Display * visual, Window readout, XEvent * horizon)
{
...
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluLookAt(0.0, 1.0, (0.0 - (firstNum * 3.0)), 0.0, 0.0, (0.0 - (firstNum *3.0)), 0.0, 2.0, 0.0);
#if DEBUG
std::cout<<"check\n";
#endif
do{
XNextEvent(visual, horizon);
#if DEBUG
std::cout<<"check\n";
#endif
switch(horizon->type)
{
...

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluLookAt(0.0, 1.0, (0.0 - (firstNum * 3.0)), 0.0, 0.0, (0.0 - (firstNum *3.0)), 0.0, 2.0, 0.0);
case KeyPress:
{
KeySym keysym;
XKeyEvent * kevent;
char buffer[1];
/* It is necessary to convert the keycode to a
* keysym before checking if it is an escape */
kevent = (XKeyEvent *)horizon;
if ((XLookupString((XKeyEvent *)horizon, buffer, 1, &keysym, NULL) == 1) && (keysym == (KeySym)XK_Escape))
{
exit(0);
}
else
{
if (stage <= 9)
{
switch(stage)
{
case 1:
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
allPoints[2] = new geopoint((0.0 - firstNum), 0.0, 0.0);
allPoints[3] = new geopoint(firstNum, 0.0, 0.0);
allPoints[4] = new geopoint(0.0, 0.0, (0.0 - firstNum));
allPoints[5] = new geopoint(0.0, 0.0, firstNum);
allLines[1] = new geoline(allPoints[2], allPoints[3]);
allLines[1]->drawShape();
std::cout<<"First, we must draw a line twice the length of the original dimension.\n";
std::cout<<"We cannot use this line to build the new cube directly, as it would be more than twice the size of the initial cube.\n";
stage++;
break;
}


I have tried pretty much everything, so if you are reading this and you can suggest anything, please respond.

Darth_Malloc
08-07-2012, 07:18 PM
Just an update.

Here is the main function, if that gives any indication of the problem.



/* A simple program to show how to set up an X window for OpenGL rendering.
* X86 compilation: gcc -o -L/usr/X11/lib main main.c -lGL -lX11
* X64 compilation: gcc -o -L/usr/X11/lib64 main main.c -lGL -lX11
*/
#include <iostream>
#include <string>
#include <stdlib.h>
#include <GL/glx.h> /* this includes the necessary X headers */
#include <GL/gl.h>
#include <X11/X.h> /* X11 constant (e.g. TrueColor) */
#include <X11/keysym.h>
#include "double_cube.h"
#define DEBUG true

int main(int argc, char ** argv)
{
static int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None};
static int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
Display * dpy;
Window win;
float first;
GLfloat start, xAngle = 42.0, yAngle = 82.0, zAngle = 112.0;;
GLboolean doubleBuffer = GL_TRUE;
XVisualInfo * vi;
Colormap cmap;
XSetWindowAttributes swa;
GLXContext cx;
XEvent * event;
GLboolean needRedraw = GL_FALSE, recalcModelView = GL_TRUE;
event = new XEvent;
int dummy;


dpy = XOpenDisplay(NULL);
if (dpy == NULL)
{
fatalError("could not open display");
}

/*** (2) make sure OpenGL's GLX extension supported ***/

if(!glXQueryExtension(dpy, &dummy, &dummy))
{
fatalError("X server has no OpenGL GLX extension");
}

/*** (3) find an appropriate visual ***/

/* find an OpenGL-capable RGB visual with depth buffer */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf);
if (vi == NULL)
{
vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf);
if (vi == NULL) fatalError("no RGB visual with depth buffer");
doubleBuffer = GL_FALSE;
}
/*** (4) create an OpenGL rendering context ***/

/* create an OpenGL rendering context */

cx = glXCreateContext(dpy, vi, /* no shared dlists */ None, /* direct rendering if possible */ GL_TRUE);
if (cx == NULL)
{
fatalError("could not create rendering context");
}

/*** (5) create an X window with the selected visual ***/

/* create an X colormap since probably not using default visual */
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = KeyPressMask | ExposureMask | ButtonPressMask | StructureNotifyMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1000, 1500, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa);
XSetStandardProperties(dpy, win, "main", "main", None, argv, argc, NULL);
/*** (6) bind the rendering context to the window ***/
glXMakeCurrent(dpy, win, cx);
/*** (7) request the X window to be displayed on the screen ***/

XMapWindow(dpy, win);

/*** (8) configure the OpenGL context for rendering ***/

glEnable(GL_DEPTH_TEST); /* enable depth buffering */
glDepthFunc(GL_LESS); /* pedantic, GL_LESS is the default */
glClearDepth(1.0); /* pedantic, 1.0 is the default */

/* frame buffer clears should be to black */
glClearColor(0.0, 0.0, 0.0, 0.0);

/* set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
/* establish initial viewport */
/* pedantic, full window size is default viewport */
glViewport(0, 0, 1000, 1500);
glMatrixMode(GL_MODELVIEW);

std::cout<<"Press left mouse button to rotate around X axis.\n";
std::cout<<"Press middle mouse button to rotate around Y axis.\n";
std::cout<<"Press right mouse button to rotate around Z axis.\n";
std::cout<<"Press ESC to quit the application\n";
std::cout<<"Press the any other key to advance to the next stage.\n";
std::cout<<"Please note: due to the limited capacity of OpenGL to display curved lines, a small amount of imprecision may occur in results.\n";
/*** (9) dispatch X events ***/
while (1)
{
if (recalcModelView)
{
glMatrixMode(GL_MODELVIEW);
/* reset modelview matrix to the identity matrix */
glLoadIdentity();
/* move the camera back three units */
glTranslatef(0.0, 0.0, -3.0);
/* rotate by X, Y, and Z angles */
glRotatef(xAngle, 0.1, 0.0, 0.0);
glRotatef(yAngle, 0.0, 0.1, 0.0);
glRotatef(zAngle, 0.0, 0.0, 1.0);
recalcModelView = GL_FALSE;
needRedraw = GL_TRUE;
}
if (needRedraw)
{
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glXSwapBuffers(dpy, win);
#if DEBUG
std::cout<<"starting\n";
#endif
double_cube(start, doubleBuffer, dpy, win, event);
needRedraw = GL_FALSE;
}
}
return 0;
}


If this gives any indication of the problem, please let me know.

Darth_Malloc
08-12-2012, 11:26 AM
I am sorry if this is a noob issue, but I really could use some help. I have no trouble with the mathematical aspect of OpenGL programming, but this is my first OpenGL project and I am unfamiliar with some of the specific rules of picture display, particularly in conjunction with X11. Please understanding that I am not asking for help out of laziness, but out a desire to learn from people with more experience with OpenGL. I would therefore greatly appreciate if someone might explain what aspect of the code is preventing the image from displaying in the window.

Lazy Foo'
08-12-2012, 04:54 PM
If the only thing you're getting is a blank window, you want to make sure your rendering code is as minimal as possible so you can easily tell what's wrong. It's always best to build in testable chunks.

First thing I would check is your rendering context even rendering to the screen. What I would do is change the color of glClearColor to see if that changes anything. If it does then you would try to render a 2D polygon on the screen to see if you get that work

Darth_Malloc
08-13-2012, 10:08 PM
I think that helps. I am, however, a bit fuzzy on how X11 programming should be integrated with OpenGL. The images rendered before, but now that I am trying to use X11 for user input, I am just getting a empty black window. I was hoping that someone might be able to suggest how to fix that.

Dan Bartlett
08-14-2012, 01:18 AM
You're meant to call glXSwapBuffers after you've drawn to the back buffer, not before.

You're only executing the code protected by "if (needRedraw)" once, and since the drawing code happens after the glXSwapBuffers, nothing gets drawn at all.

It's also a bit unclear what you're trying to do with matrices, with the calls to "glMatrixMode(GL_MODELVIEW);" + "glMatrixMode(GL_PROJECTION);" directly after each other. There's very little you want to be doing in GL_PROJECTION mode (generally only a glLoadIdentity followed by a gluPerspective/glFrustum/glOrtho/gluOrtho2 - see http://sjbaker.org/steve/omniv/projection_abuse.html ), as most code usually happens in GL_MODELVIEW mode.