PDA

View Full Version : I am unable to draw anything.



holland01
01-24-2012, 09:33 AM
Despite what it seems like the issue may be, I'm entirely unable to draw in OpenGL unless I use something like Freeglut to do the drawing for me. For whatever reason, I have a feeling that my drivers are totally screwed as this wasn't the case before.

I've tried this using SDL and Qt especially, and both implementations result in something poor happening graphically.

I'm using Mesa on Ubuntu (libgl1, in fact), and would like to hear from others who have had similar experiences such as this, and could comment on their experiences as well. The issue is more so drivers, I think (I have a Gateway nv57h26u with an INTEL HD Graphics card - which, honestly, is complete shite).

As far as basic setup, nothing more than Qt Creator, Ubuntu, and GCC for the compiler (C++ - NOT c).

What could be going on here?

thokra
01-24-2012, 09:36 AM
If FreeGLUT functions can successfully render, why should the drivers be the first to blame and not yourself? Care to post some code?

abbelicious
04-10-2012, 12:53 PM
I have a similar problem. I'm using freeglut though for window control. I'm using glDrawElements to render a cube. My friend who's also working on the same project as me is able to run the program without any problems.

The thing is I do not get any compile errors (tried glGetError as well). The clear color appears, it simply wont draw my object. I can post some code if you like however it should be correct, it's rather my drivers, libraries, something- that causes the problem.

Dark Photon
04-11-2012, 05:10 AM
The clear color appears, it simply wont draw my object.
Yeah, feel free to post a little code. Be sure to include Also, post the output of these two commands:


echo $DISPLAY
glxinfo | grep ':'

Also, here's a little "kick-the-tires" test program you can try (just some random code I found lying around):



#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glu.h>

#include <stdio.h>

float rotation_angle=0;
int aa=1;

void
reshape(int width, int height)
{
glViewport(0, 0, width, height);
}

void
mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) {
aa=!aa;
glutPostRedisplay();
}
}


void
display()
{
int err=0;
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1,1,-1,1,-1,1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(rotation_angle, 0,0,1);

glColor4f(1,0,0,1);

//#define AA_PRIMITIVE GL_POLYGON_SMOOTH
#define AA_PRIMITIVE GL_MULTISAMPLE_ARB
if(aa) {
glEnable(AA_PRIMITIVE);
printf("aa on\n");
} else {
printf("aa off\n");
glDisable(AA_PRIMITIVE);
}

glRectf(-.5,-.5,.5,.5);

glutSwapBuffers();
err = glGetError();
if(err)
fprintf(stderr, "%s\n", gluErrorString(err));
}

int
main (int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE);
glutCreateWindow(argv[0]);

glutDisplayFunc(display);
glutMouseFunc(mouse);
glutReshapeFunc(reshape);

glutReshapeWindow(400,400);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

printf("%s\n",glGetString(GL_RENDERER));

{
int toto[4];
glGetIntegerv(GL_MULTISAMPLE_ARB, toto);
printf("samples: %d\n", toto[0]);
}

//glClearColor(1,1,1,0);
rotation_angle=30;

glutMainLoop();
return 0;
}

abbelicious
04-11-2012, 08:53 AM
Thanks for helping out Dark Photon. This is my video specifications:


>>echo $DISPLAY
:0.0

>>glxinfo | grep ':'
name of display: :0.0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: ATI
server glx version string: 1.4
server glx extensions:
client glx vendor string: ATI
client glx version string: 1.4
client glx extensions:
GLX version: 1.4
GLX extensions:
OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: ATI Radeon HD 5800 Series
OpenGL version string: 4.1.11005 Compatibility Profile Context
OpenGL shading language version string: 4.10
OpenGL extensions:
91 GLXFBConfigs:



Also, here's a little "kick-the-tires" test program you can try (just some random code I found lying around)

I tried your testprogram and it worked fine. Red square appeared and was clickable. My guess is the problem lies in glDrawElements, since glRectf() worked. Here's some of my code, I removed a lot of unnecessary code, our goal is to draw lots of cubes in different patterns but right now I'm just putting out 1 cube. I did not include the shaders as they are very inactive at the moment, just doing the matrix multiplications. So let me know if you need more, I thought I'd keep it simple at first.


void init(void)
{
dumpInfo();

// GL inits
glClearColor(0.0,0.1,0.2,0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
printError("GL inits");

initKeymapManager();

// Load and compile shader
program = loadShaders("fract.vert", "fract.frag");
printError("init shader");

// Allocate and activate Vertex Array Objects
glGenVertexArrays(1, &amp;vertexArrayID);
glBindVertexArray(vertexArrayID);

// Allocate Vertex Buffer Objects
glGenBuffers(1, &amp;vertexBufferID);
glGenBuffers(1, &amp;indexBufferID);

// VBO for vertex data
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(glGetAttribLocation(program, "in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(glGetAttribLocation(prog ram, "in_Position"));
printError("init vertices");

//VBO for index data
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*sizeof(GLubyte), cubeIndices, GL_STATIC_DRAW);

//Add a cube to object list
Cube obj;
memcpy(obj.v, vertices, numVertices*sizeof(GLfloat));
obj.vertexArrayObjID = vertexArrayID;
obj.vertexBufferObjID = vertexBufferID;
obj.indexBufferObjID = indexBufferID;
mylist = list_create(obj);
createCube(obj,mylist); // Uploads a cube object to the shader, I belive alot of above is unnecessary but im not in a position to
}

void display(){
keyboardMovement();
GLfloat spacing[3] = {0, 0, 0};
GLfloat color[3] = {0.2, 0.4, 0.1};
// clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Transformation matrices
GLfloat camera[16], rot[16], trans[16], totalMatrix[16];

lookAt( cameraPosX, cameraPosY, cameraPosZ, // Camera pos
lookAtPosX, lookAtPosY, lookAtPosZ, // Look at pos
0.0, 1.0, 0.0, // Up vector
camera);
printError("pre display");

// Initialize matrices
T(0, 0, 0, trans);

// Cube
drawCubes(mylist,spacing,camera,projectionMatrix,t rans,0,1,color);
}

/*
This is a work in progress so it might be a bit hard to understand.
What it does: Draws an object from cubelist 'n' times, with a distance of 'spacing' from each other. Offset is always 1 atm.
cm - camera matrix, pm - projection matrix, tm - translation matirx.
*/
void drawCubes(const CubeList *l, GLfloat* spacing, GLfloat *cm, GLfloat *pm, GLfloat* tm, int offset, int n, GLfloat *color){
CubeList *tl = l;
Cube c;
int i,j;
GLfloat total_m[16], camera_m[16], projection_m[16], translation_m[16], local_trans[16], colorstep[3];
memcpy(camera_m, cm, 16*sizeof(GLfloat));
memcpy(projection_m, pm, 16*sizeof(GLfloat));

GLfloat cspacing[] = {0,0,0};
for(i=0;i<3;i++){
colorstep[i] = (1.0-color[i])/n;
}

//Step to the right offset
for (i=0;i<offset;i++)
{
if(tl != NULL)
tl = tl->next;
}

//Draw n elements
for(i=0;i<n;i++)
{
if(tl != NULL){
c = list_get_cube(tl);

//Transformations
memcpy(translation_m, tm, 16*sizeof(GLfloat));
T(cspacing[0],cspacing[1],cspacing[2], local_trans);
Mult(translation_m,local_trans,translation_m);
Mult(camera_m, translation_m, total_m);
Mult(projection_m, total_m, total_m);

//Upload to shader
glUniformMatrix4fv(glGetUniformLocation(program, "totalMatrix"), 1, GL_TRUE, total_m);
glUniform3f(glGetUniformLocation(program, "inColor"), color[0], color[1] ,color[2]);
glBindVertexArray(c.vertexArrayObjID); // Select VAO
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_BYTE, 0L);

for(j=0;j<3;j++){
color[j] += colorstep[j];
cspacing[j] += spacing[j];
}
}
}
}


Peace

Dark Photon
04-11-2012, 04:57 PM
Nothing's just leaping out of the code at me. There are a lot of logic things that could be wrong here. I'd start with something that works and morph it gradually (with intermediate testing) into your simple case that doesn't.

abbelicious
04-12-2012, 03:38 AM
Okay. Yeah I'll do that.