Not working... OpenGL
Moderator: Coders of Rage
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Not working... OpenGL
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
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
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Not working... OpenGL
Post some code or we have no idea what your trying to do
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Not working... OpenGL
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.
Still learning...
I mean... really...
I don't get it. Just a sec.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Not working... OpenGL
Okay...
Please just tell me what the heck I'm supposed to do,
because I doubt that this is close to being right....
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
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);
}
I really don't understand a lot of what to do.
Thanks,
-Benjamin
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Not working... OpenGL
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?
- szdarkhack
- Chaos Rift Cool Newbie
- Posts: 61
- Joined: Fri May 08, 2009 2:31 am
Re: Not working... OpenGL
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.
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.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Not working... OpenGL
I really don't understand what the modelview matrix and projection matrix are.
Could someone please explain it to me?
Thanks,
-Benjamin
Could someone please explain it to me?
Thanks,
-Benjamin
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Not working... OpenGL
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.
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.
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Thu Jun 23, 2011 11:12 am
Re: Not working... OpenGL
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!
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!
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Not working... OpenGL
Thanks guys.