Advertisement

understanding viewport opengl

Started by October 27, 2018 03:46 PM
16 comments, last by noname999 6 years ago

Dear gamedev,

i'm trying to understand the opengl viewport.

As i understand viewport is used for the resolution.

first question:

what i learned is that for windows i need <windows.h>, <gl/gl.h>, <gl/glu.h> and <stdlib.h>

for linux <windows.h> can be replaced with <x11/lib.h>

is this correct?

second question is about the viewport and like some explanation why i did get errors.

i expect to get a window with border and a error that no materix and/or no collor is defined.

first code:

int main(void)
{
    GL_VIEWPORT(0, 0, 800, 600);
}

result

ERROR: term does not evaluate to a function taking 4 arguments.

 

second code:

void display()
{
    glViewport(0, 0, 800, 600);
}

result:

ERROR: entry point must be defined.

 

last question:

why can't the resolution directly be placed in the viewport and what is the difference in the GL_VIEWPORT or glViewport?

i'm using c++ and try to prevend the use of aditional frameworks (keep it basic).

as you figgured out i try to program crossplatform.

 

 

17 minutes ago, noname999 said:

ERROR: entry point must be defined

You need a main() in c++

Find a tutorial/book that was created in the last 5 years and don't try to figure this stuff out with trial and error. Put more effort into learning your chosen language over OpenGL for a few weeks.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

Dear fleabay ,

some examples that i come accros are from the opengl site that would sugeste:

int main()
{
    void GL_VIEWPORT(0, 0, 800, 600);
}

gives syntax error.

 

and you are right the c++ book seems to be from 2001......?

 

GL_VIEWPORT is not a function. The all-caps defines are meant to be used instead of magic numbers as parameters to OpenGL calls.

For example there are a ton of these defines in glew.h that are nothing more than hex values.


//more more more
#define GL_DEPTH_RANGE 0x0B70
#define GL_VIEWPORT 0x0BA2
#define GL_SCISSOR_BOX 0x0C10
#define GL_SCISSOR_TEST 0x0C11
#define GL_MAX_VIEWPORTS 0x825B
#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C
//more more more

 

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

3 hours ago, noname999 said:

what i learned is that for windows i need <windows.h>, <gl/gl.h>, <gl/glu.h> and <stdlib.h>

Then you're learning from a very, very old and outdated source.  The glu.h has been depreciated for a very long time now.  Also, you posted this is C++ so why is your tutorial using stdlib.h?  

Try learning modern OpenGL if you're going to learn OpenGL: https://learnopengl.com

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

i have some thing working under windows

int main() {

    void WINAPI glViewport(GLint, GLint, GLsizei, GLsizei);

};

hoped i did not have to use the winapi.
 

how will this winapi function under linux?
i know i should test befor asking...

@ CrazyCdn

<stdlib.h>  was from test and forgot to remove. can be ignored

Advertisement
17 minutes ago, noname999 said:

how will this winapi function under linux?

Like a lead balloon.

You can't write any significant C++ to be multi-platform without branching and preprocessing directives. You have to have platform dependent code for each. External libraries will handle this for you by hiding the details.

You have a TON to learn, just with C++ and OpenGL, before you even think about multi-platform.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

i already learned that system specific headers can be shifted using preprocessing.

for some tasks i arranged seperate files that are going to hande platform(windows, linux) specific tasks.

yes i have to learn alot and have alot of pre-assumptions about things. like windows.h won't work on linux becose it uses the win32 api.

i hoped that opengl that is cross platform could be used with unified code.

perhaps there is a great book for crosplatform becose i only find some books with java or not so great without opengl that says crossplatform "gui development"/"game developer" that was text based

To echo others, I wouldn't worry about cross-platform development right now. Among other things, if you're serious about portability, it's not a given that you'll want to use OpenGL across all platforms. (For example, although OpenGL and OpenGL ES still work on macOS/iOS and will probably do so for a while, they're deprecated there.)

This is just opinion, but I'd suggest trying to get something working on a single platform (any platform - whatever's convenient) without thinking about other platforms for now. Getting a basic C++ OpenGL application off the ground poses plenty of challenges even without worrying about portability.

Also keep in mind that C++ with OpenGL isn't your only option. There are many other languages to choose from, other graphics APIs you can use, and many, many higher level frameworks/libraries/engines/wrappers you can use to simplify things (including portability). C++ and OpenGL are perfectly reasonable choices, but just be aware that there are other options.

21 hours ago, noname999 said:

first question:

what i learned is that for windows i need <windows.h>, <gl/gl.h>, <gl/glu.h> and <stdlib.h>

for linux <windows.h> can be replaced with <x11/lib.h>

is this correct? 

 

Wrong.

On Windows you will only get the extremely outdated OpenGl 1.1 if you go that way.

You will also waste much time doing platform dependend quirky code to set up windows and contexts, without getting anywhere near actually using OpenGL.

Forget your outdated 2001 book!

 

Use a modern tutorial and modern libraries, like GLFW (sets up the window and contexts and input for you in a cross platform way) and GLAD (loads  function pointers, so you can use modern OpenGL functions)!

This topic is closed to new replies.

Advertisement