glOrtho problems.....

Started by
12 comments, last by falledAngel 18 years ago
Hi people, I need to build a 2D application, and I've choose glOrtho perspective, but when I'm trying to put some color on the view all becomes black, any suggestion? P.D: I found some code that let me put some text on the view, with GLPrint and Buildfont but I can't see nothing. Thank you, ans sorry for my bas writing! visca el BARÇA!!!!
I spent most of my money on booze, women and cars. The rest I just wasted. George Best
Advertisement
It would be good to see some code into what you are doing, it probably could be that you are not clearning the buffer or drawing nothing. Various things could be wrong.

On the other hand you could also take Nehe Lesson 1 and change the gluPerspective to glOrtho and make modifications to it.


The more applications I write, more I find out how less I know
If you want only 2D try to set up the orthographic projection with:
gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
As you can see this function has no depth parameter as glOrtho() has.

If you can use GLUT try using this function for text output.

void outputText(int x, int y, char *string){  int len, i;  glRasterPos2f(x, y);  len = (int) strlen(string);  for (i = 0; i < len; i++)  {    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string);  }};
People of the Earth unite!
Quote:i've choose glOrtho perspective


I think saying "glOrtho perspective" is an oxymoron. There are two types of projections: orthographic and perspective. With orthographic projection objects appear same size if same dimension regardless of depth while with perspective projection objects placed further in depth appear smaller than the nearer objects. I think it is not correct to say "glOrtho perspective" since this function sets up orthographic projection not the perspective one. Please correct me if I am wrong since I am not absolutely sure about this terminology.
People of the Earth unite!
Thank you so much to answer me.

I've solved the problem I had when all becames black
I choose glColor4i and if I use glColor3f doesn't became black,
but now, the problem is that the color is applied as a tint on all objects on the scene. What's the problem?

the code:
...
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { Initialize The GL Window
if (height==0) { height=1;
}
glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, 1, 5);
glMatrixMode(GL_MODELVIEW); ///!!!!This can be a possible error glLoadIdentity(); ///!!!!Maybe change to another MODe????
}
...
int DrawGLScene(GLvoid) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, textura[0]);
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-5.0f); // Move Left And Into The Screen
if (bMouseEsq) {
setColor(1,1,1,1);
}
glBegin(GL_QUADS);
//!!Don't worry about this part, m is menu,with x pos, y pos, width an height, setGLcoord convert the "coords" in pixels.
glTexCoord2f(0.0f, 1.0f);
point p;
p=setGLCoord(m.getXPos(),m.getYPos());
glVertex2f(p.x, p.y);
glTexCoord2f(0.0f, 0.0f);
p=setGLCoord(m.getXPos(),m.getYPos() + m.getHeight());
glVertex2f(p.x, p.y);
glTexCoord2f(1.0f, 0.0f);
p=setGLCoord(m.getXPos() + m.getWidth(),m.getYPos() + m.getHeight());
glVertex2f(p.x, p.y);
glTexCoord2f(1.0f, 1.0f);
p=setGLCoord(m.getXPos() + m.getWidth(),m.getYPos());
glVertex2f(p.x, p.y);
glEnd()...


What can I do???
I spent most of my money on booze, women and cars. The rest I just wasted. George Best
...
glBegin(GL_QUADS);
glColor3f(0.5f,0.5f,1.0f);
p=setGLCoord(10,10);
glVertex2f(p.x, p.y);
p=setGLCoord(10,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,10);
glVertex2f(p.x, p.y);
glEnd();

}
I spent most of my money on booze, women and cars. The rest I just wasted. George Best
glColor4* is RGBA meaning implies if alpha is max then it becomes transparent I think(not sure exactly how to describe it of my explanation is correct). So you would have to choose correct value of alpha in that case. But if you don't want alpha then just stick to glColor3*.

Coming to restricting the tint with the texture you would have to use GL_REPLACE as one of the texture environment (using glTexEnv*) while binding the texture to the polygon for it to ignore the color.

Hope this helps.


The more applications I write, more I find out how less I know
Sorry I don't know how apply glTextEnv, but a very stange think is happening now.

glBegin(GL_QUADS);
glColor3f(222,231,0);
p=setGLCoord(10,10);
glVertex2f(p.x, p.y);
p=setGLCoord(10,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,200);
glVertex2f(p.x, p.y);
p=setGLCoord(20,10);
glVertex2f(p.x, p.y);
glEnd();

glBegin(GL_QUADS);
glColor3f(22,2,233);
p=setGLCoord(70,10);
glVertex2f(p.x, p.y);
p=setGLCoord(70,200);
glVertex2f(p.x, p.y);
p=setGLCoord(121,200);
glVertex2f(p.x, p.y);
p=setGLCoord(220,10);
glVertex2f(p.x, p.y);
glEnd();

The first picture I see it in yellow tint color, but the second one, erases the tint, on the second object, and in the menu posted before. Can be the mode of the projection Matrix??????
I spent most of my money on booze, women and cars. The rest I just wasted. George Best
I'm lost. Maybe it's the way I declare de Texture?????

H-E-L-P

int LoadGLTextures() {
int Status = FALSE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage, 0, sizeof(void *)*1);
if (TextureImage[0]=LoadBMP("Imatges/untitled2.bmp")) {
Status = TRUE;
glGenTextures(1, &textura[0]);
glBindTexture(GL_TEXTURE_2D, textura[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

}
if (TextureImage[0]) {
if (TextureImage[0]->data) {
free(TextureImage[0]->data);
}
}
return Status;
}

int InitGL(GLvoid) {
nFitxer = "Imatges/untitled2.bmp";
m.setXPos(160);
m.setYPos(360);
m.setWidth(300);
m.setHeight(50);
m.setFitxer(nFitxer);

if (!LoadGLTextures()) {
return FALSE;
}
glEnable(GL_TEXTURE_2D);
glClearColor(0.3f, 0.3f, 0.3f, 0.5f);
glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_BLEND);
BuildFont();
return TRUE;
}
I spent most of my money on booze, women and cars. The rest I just wasted. George Best
Quote:Original post by CRACK123
glColor4* is RGBA meaning implies if alpha is max then it becomes transparent I think(not sure exactly how to describe it of my explanation is correct).


Actually, when the alpha value increases, things become more opaque, unless you play with the blending operations, in which case it can be changed.

Anyway, going over your code fairly quickly, I've noticed the colours you're using in the functions are completely inappropriate (I've done it before, so don't feel too bad about it). What you need to do is ensure that all of your colours are in the ranges 0.0f to 1.0f when using the float/double functions, otherwise you're going to end up with a lot of problems.

Also, the internal format you're using for the images shouldn't include numbers (your '3' for example), but should include the defined types found in the OpenGL header (GL_RGB, GL_RGBA, etc.).

Finally, I see you've enabled blending, but you haven't specified the blending function you want to use. The one most people tend to go with is glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA), since that does all of the alpha blending fairly well. Also, you might want to enable alpha testing (glEnable(GL_ALPHA_TEST)), and set some cut-off value so things don't look dodgy when the alpha values get too low (glAlphaFunc(GL_GREATER,0.2f)).

Let us know if this helps, or if it fixes the problem, or if it still persists (in which case I'm sure somebody (if not myself) will be around to help you through it).

This topic is closed to new replies.

Advertisement