Page 1 of 1

Not working... OpenGL

Posted: Wed Oct 19, 2011 7:38 pm
by Benjamin100
Hey guys,

I'm trying to just render a basic shape in OpenGL.
It doesn't appear to be putting anything on the screen.
I have it trying to make a triangle using glVertex3f. First of all,
can I use 3 dimensions for a triangle?
Also, is there some common problem that causes the window to come up blank?
Or should I be putting some code up?

I tried following some tutorials, but it seems like I must be missing something.
What are the steps to getting it on the screen?
Is there something major I have to do after setting the vertex coordinates?


Thank you,

-Benjamin

Re: Not working... OpenGL

Posted: Wed Oct 19, 2011 7:49 pm
by short
Post some code or we have no idea what your trying to do

Re: Not working... OpenGL

Posted: Wed Oct 19, 2011 7:53 pm
by Benjamin100
Well, my code probably won't make much sense cause I have very little of an idea as to what I'm trying to do...
Still learning...
I mean... really...
I don't get it. Just a sec.

Re: Not working... OpenGL

Posted: Wed Oct 19, 2011 7:57 pm
by Benjamin100
Okay...
Please just tell me what the heck I'm supposed to do,
because I doubt that this is close to being right....

Code: Select all

#include <Windows.h>
#include <cstdio>
#include <gl/gl.h>
#include <gl/GLU.h>

HWND hWnd;
HDC hDC;
HGLRC hRC;
WNDCLASS wc;
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
	switch(message)
	{
	case WM_CREATE:
		return 0;
	case WM_CLOSE:
		PostQuitMessage(0);
		return 0;
	case WM_DESTROY:
		return 0;
	default:
		return DefWindowProc(hWnd,message,wParam,lParam);
	}
}
    
void enable_opengl(HWND hWnd,HDC* hDC,HGLRC* hRC);		
void Render_It(HDC* hDC)
{

	glViewport(0,00,500,500);
    glBegin(GL_TRIANGLES);
	glVertex3f(100.0f,150.0f,0.0f);
	glVertex3f(50.0f,50.0f,0.0f);
	glVertex3f(150.0f,10.0f,0.0f);
	glEnd();
	SwapBuffers(*hDC);
	




}

void enable_opengl(HWND hWnd,HDC* hDC,HGLRC* hRC)
{
	*hDC=GetDC(hWnd);
    PIXELFORMATDESCRIPTOR pfd;
	ZeroMemory(&pfd,sizeof(pfd));
	pfd.nSize=sizeof(pfd);
	pfd.nVersion=1;
	pfd.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
	pfd.iPixelType=PFD_TYPE_RGBA;
	pfd.cColorBits=24;
	pfd.cDepthBits=16;
	pfd.iLayerType=PFD_MAIN_PLANE;
	int iFormat=ChoosePixelFormat(*hDC,&pfd);

	SetPixelFormat(*hDC,iFormat,&pfd);






	
	*hRC=wglCreateContext(*hDC);
	wglMakeCurrent(*hDC,*hRC);

}
void disable_opengl(HWND hWnd,HDC hDC,HGLRC hRC)
{
   wglMakeCurrent(NULL,NULL);
   wglDeleteContext(hRC);
   ReleaseDC(hWnd,hDC);
}



So the main function (not included) is just to set up the window, enable, render, and disable.

I really don't understand a lot of what to do.



Thanks,


-Benjamin

Re: Not working... OpenGL

Posted: Wed Oct 19, 2011 7:58 pm
by Benjamin100
Okay, I should probably say that I didn't get to finishing the whole "message" thing, which the tutorial had me doing, and I'm not used to setting up a window by myself. But is that going to affect the rendering?

Re: Not working... OpenGL

Posted: Wed Oct 19, 2011 10:22 pm
by szdarkhack
There are a few problems here. First of all, without seeing your WinMain i cannot tell if you are setting up the window correctly. If not, you won't draw anything. Second, you have not set the modelview and projection matrices and the coordinates you have given are outside of clip space (opengl will use the default identity matrix). So again, no drawing. If you are having trouble with the window creation, get SDL and let it do the job. If you do not know what modelview and projection matrices are, you need to pay closer attention to the tutorials you are reading.

By the way, calling glViewport every time you draw is unnecessary and very slow. Call it once when you initialize opengl.

Oh, and the "message" thing is rather important on Windows, you could have serious problems if you don't set your handler correctly. So do finish it.

Re: Not working... OpenGL

Posted: Thu Oct 20, 2011 7:51 pm
by Benjamin100
I really don't understand what the modelview matrix and projection matrix are.
Could someone please explain it to me?

Thanks,

-Benjamin

Re: Not working... OpenGL

Posted: Thu Oct 20, 2011 8:47 pm
by qpHalcy0n
This post goes into it a bit:
viewtopic.php?f=6&t=3874&p=44680#p44680

If you need more or have more SPECIFIC questions, then feel free to come back :) "What are these matrices?" Is not really a very forum answerable question without getting very very lengthy.

Re: Not working... OpenGL

Posted: Fri Oct 28, 2011 6:51 pm
by Rebornxeno
You might want to learn the right way from the start, learning the latest opengl core profile. Go pickup a copy of the Opengl SuperBible's latest version and give it a read.
Or, if you can't afford a book, this site is also great. http://www.arcsynthesis.org/gltut/

Oh, and a majority of problems I faced with opengl were really only caused by linker problems, so be sure to check those are correct. Have fun with computer graphics!

Re: Not working... OpenGL

Posted: Fri Oct 28, 2011 9:54 pm
by Benjamin100
Thanks guys.