understanding viewport opengl

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:
1
2
3
4
int main(void)
{
    GL_VIEWPORT(0, 0, 800, 600);
}

result

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


second code:
1
2
3
4
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.
> what is the difference in the GL_VIEWPORT or glViewport?
rtfm
man glViewport wrote:
glViewport - set the viewport
x, y
Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0).

width, height
Specify the width and height of the viewport. When a GL context is first attached to a window,
width and height are set to the dimensions of that window.
man glGet wrote:
GL_VIEWPORT
params returns four values: the x and y window coordinates of the viewport, followed by its width
and height.



> 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.
perhaps it would be simpler to use a crossplatform library than having to maintain two versions of your code.


> ERROR: term does not evaluate to a function taking 4 arguments.
> ERROR: entry point must be defined.
¿what kind of errors? (compile, linking, runtime)
when asking for code post enough code to reproduce the problem. I would say that your second code is missing `main()', I don't want to have to fill those blanks.
Last edited on
If your goal currently is to learn OpenGL, save yourself the headache of trying to roll your own cross-platform solution. As ne555 suggested, use an existing cross-platform library.

I'm not sure what you've been able to accomplish so far, so I'm just going to start from the beginning:

The following are examples of libraries capable of supporting modern OpenGL contexts:
GLFW https://www.glfw.org/ (perhaps easiest to set up?)
SFML https://www.sfml-dev.org/tutorials/2.5/window-opengl.php
Most other widget/GUI libraries also will support OpenGL, but they are probably harder to install.

To load OpenGL functions, use GLEW or GLAD:
http://glew.sourceforge.net/
https://github.com/Dav1dde/glad

The first time I tried to get OpenGL to work was a bit of a headache... luckily there are resources available like this site: http://www.opengl-tutorial.org/
That site uses GLFW in its setup examples (though the tutorials are set up to be window/GUI-agnostic)
Last edited on
Topic archived. No new replies allowed.