c++ - Black screen while trying to display drawing on screen -


i started learn opengl, , im stuck on problem, when try make resizable window, object not showing on window, , cant figure why. if can take quick wrong of big help. best regards.

#include <stdio.h> #include <stdlib.h> #include <gl/glut.h>  void initlights(); void reshape(int width, int height); void display(); void renderscene(); int w; int h; int main(int argc, char** argv) {   glutinit(&argc, argv); //metodi se predaje dva argumenta - andresa varijable koja sadrži broj argumenata iz komandne linije, te polje tih argumenata   glutinitdisplaymode(glut_double);    glenable(gl_lighting);   glutinitwindowsize(w, h); //dimenzije prozora u pikselima   glutinitwindowposition(0, 0); //pozicija gornjeg lijevo kuta u kojem će se scena iscrtati, prvi argument je x, drugi y   glutcreatewindow("primjer 1"); //stvaranje prozora u kojem će se iscrtati scena ("naziv prozora")   glutdisplayfunc(display); //registracija metode display, vraća podatak tipa int koji se može koristiti kao identifikator prozora koji se kasnije koristi za uništavanje prozora   glutreshapefunc(reshape); //registracija metode reshape   glutmainloop(); //beskonačna petlja osluškivanja, generiranja događaja pozivanje registriranih metoda koja obrađuje događaje } void initlights() {   // set light colors (ambient, diffuse, specular)   glfloat lightka[] = {.5f, .5f, .5f, 1.0f}; // ambient light   glfloat lightkd[] = {.7f, .7f, .7f, 1.0f}; // diffuse light   glfloat lightks[] = {1, 1, 1, 1}; // specular light   gllightfv(gl_light0, gl_ambient, lightka);   gllightfv(gl_light0, gl_diffuse, lightkd);   gllightfv(gl_light0, gl_specular, lightks);   // position light   float lightpos[4] = {0, 0, 20, 1}; // positional light   gllightfv(gl_light0, gl_position, lightpos);   glenable(gl_light0); // must enable each light source after configuration }  void display() { //iscrtavanje scene, radi se pozivom metode glutdisplayfunc(display); kojoj kao argument predajemo pokazivač na samu metodu   glclearcolor(0.0f, 0.0f, 0.0f, 1.0f); //brisanje površine platna, boja pozadine platna   glclear(gl_color_buffer_bit); //popunjavanje čitave površine platna prethodno definiranom bojom   glloadidentity();   // crtanje scene:   renderscene();   glutswapbuffers(); }  void toperspective(){   gldisable(gl_depth_test); //isključivanje provjere z-spremnika koji se koristi u 3d sceni   glviewport(0, 0,w, h); //definicija dijela prozora koji prikazuje samu scenu    glmatrixmode(gl_projection);   glloadidentity();   gluperspective(60, (double)w/(double)h, 1, 256);   glmatrixmode(gl_modelview);   glloadidentity();    }  void reshape(int width, int height) { //funkcija koja se koristi za promjenu veličine prozora w = width; h = height; toperspective(); }  void renderscene() {   glpointsize(6.0f);   glcolor3f(0.0f, 1.0f, 1.0f);    glbegin(gl_points);   glvertex2i(50, 50);   glvertex2i(150, 150);   glvertex2i(2, 2);   glvertex2i(4, 4);   glend();    glbegin(gl_line_strip);   glvertex2i(50, 50);                 glvertex2i(150, 150);                glvertex2i(50, 150);   glvertex2i(50, 50);   glend();   glvertex2i(250, 250);               } 

in code, camera located @ (0,0,0) due modelviewmatrix identity matrix. projection constructed nearplane @ 1, means model, drawn @ z=0 outside view frustum , gets culled away.

another problem: calling glvertex2i @ least once outside of glbegin/glend results in opengl error.

regarding coordinates: note, drawing in opengl not happen in pixel coordinates unless specify appropriate projection so.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -