Can't draw in opengl in visual studio 2012

El_Loco

I am trying to figure out how to make opengl work in Windows 8.1 using Visual Studio 2012.

My program compiles and runs, but nothing happens in the windows which is created, I can't even change background color or see the mouse.

My program looks as follows:

main.cpp

#include <cstdio>
#include <iostream>
#include "simpleViewer.h"

using namespace std;

int main(int argc, char **argv){
simpleViewer Viewer;
Viewer.initOpenGL(argc, argv);
Viewer.run();
}

simpleViewer.h

#pragma once
#ifndef _SIMPLEVIEWER_H_
#define _SIMPLEVIEWER_H_
#include "GL\GL\glut.h"
#include <iostream>
enum DisplayModes {
DISPLAY_MODE_OVERLAY,
DISPLAY_MODE_DEPTH,
DISPLAY_MODE_IMAGE
};


class simpleViewer 
{
public:
simpleViewer(void);
~simpleViewer(void);
virtual void run();
virtual void initOpenGL(int argc, char **argv);
virtual void initOpenGLHooks();
virtual void display();
virtual void displayPostDraw(){};
DisplayModes m_eViewState;
private:
static simpleViewer* ms_self;
static void glutIdle();
static void glutDisplay();

};
#endif

and simpleViewer.cpp

#include "simpleViewer.h"

#define GL_WIN_SIZE_X   1280
#define GL_WIN_SIZE_Y   1024

// Undeprecate CRT functions
#ifndef _CRT_SECURE_NO_DEPRECATE 
#define _CRT_SECURE_NO_DEPRECATE 1
#endif

simpleViewer* simpleViewer::ms_self;
simpleViewer::simpleViewer(void)
{
ms_self = this;
}


simpleViewer::~simpleViewer(void)
{
}

void simpleViewer::initOpenGL(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(GL_WIN_SIZE_X, GL_WIN_SIZE_Y);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow ("Test");
//  glutFullScreen();
glutSetCursor(GLUT_CURSOR_NONE);
initOpenGLHooks();
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glClearColor(1.0f,0.0f,0.0f,1.0f);
}
void simpleViewer::initOpenGLHooks()
{
glutDisplayFunc(glutDisplay);
glutIdleFunc(glutIdle);
}
void simpleViewer::run(){
glutMainLoop();
}

void simpleViewer::display(){
glBegin(GL_TRIANGLES);
glColor3f(1.0,0,0);
glVertex3f(0.1,0,0);
glVertex3f(0,0,0);
glVertex3f(0,0,0.1);
glEnd();
glFlush();

}
void simpleViewer::glutIdle(){
glutPostRedisplay();
}
void simpleViewer::glutDisplay(){
        simpleViewer::ms_self->display();
}

I have checked so that it really goes into display(), but nothing happens. The background is totally white even if it should be red.

genpfault

You've requested double-buffering via GLUT_DOUBLE.

Use glutSwapBuffers() instead of glFlush() at the end of simpleViewer::display().

glClearColor() only latches some state. glClear() actually does the clear. Add a glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) at the top of simpleViewer::display().

That triangle is wonky for the default projection/modelview matrices. Try this instead:

glBegin( GL_TRIANGLES );
glVertex2i( 0, 0 );
glVertex2i( 1, 0 );
glVertex2i( 1, 1 );
glEnd();

You'll probably want to change the triangle color too. Red on red is pretty hard to see :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I can't make SDL + OpenGL work in Visual Studio 2012

From Dev

can't draw object in openGL

From Dev

Can't install Visual Studio 2012 Express for Phone 8.0 developement

From Dev

Can't run unit test Visual Studio 2012 Ultimate

From Dev

Visual Studio 2012: can't connect to sharepoint site

From Dev

Can't install Visual Studio 2012 Express for Phone 8.0 developement

From Dev

Can't install BenchmarkDotNet 0.10.2 on Visual Studio Ultimate 2012

From Dev

Visual Basic using Visual Studio 2012 with Access! Can't get image url's to load into picture box

From Dev

How would I start an OpenGL project in visual studio 2012?

From Dev

Debug issue for OpenGL while using Visual Studio 2012

From Dev

Can you use SignalR with Visual Studio 2012?

From Dev

Can not install visual studio ultimate 2012

From Dev

visual studio 2012 debugger doesn't work

From Dev

Project doesn't open on Visual Studio 2012

From Dev

Visual Studio: Won't draw rectangle in a subwindow

From Dev

Why I can't see the debug output when I run a test in Visual Studio 2012?

From Dev

Can't see emulator selection option in visual studio 2012 for windows phone

From Dev

MTM With Visual Studio 2012 - Can't see Web Access with update 4

From Dev

Visual Studio 2012 new ASP Web Forms Application can't access textboxes from aspx file

From Dev

Why I can't see the debug output when I run a test in Visual Studio 2012?

From Dev

Can't seem to correctly add Helix Toolkit to my C# (Visual Studio Express 2012) project

From Dev

can't catch "ctor subscript out of range" exception in visual studio 2012

From Dev

Can't get OpenGL 3.3 draw a triangle, no errors thrown

From Dev

Can't draw a triangle with OpenGL ES 2.0 on android

From Dev

OpenGL: Can't draw vertices generated by a compute shader stored in SSBO

From Dev

Can't draw point in Android OpenGL ES 2.0

From Dev

Can't draw in OpenGL with pixel precision (not using fixed function pipeline)

From Dev

Can't draw point in Android OpenGL ES 2.0

From Java

How can I switch themes in Visual Studio 2012

Related Related

  1. 1

    I can't make SDL + OpenGL work in Visual Studio 2012

  2. 2

    can't draw object in openGL

  3. 3

    Can't install Visual Studio 2012 Express for Phone 8.0 developement

  4. 4

    Can't run unit test Visual Studio 2012 Ultimate

  5. 5

    Visual Studio 2012: can't connect to sharepoint site

  6. 6

    Can't install Visual Studio 2012 Express for Phone 8.0 developement

  7. 7

    Can't install BenchmarkDotNet 0.10.2 on Visual Studio Ultimate 2012

  8. 8

    Visual Basic using Visual Studio 2012 with Access! Can't get image url's to load into picture box

  9. 9

    How would I start an OpenGL project in visual studio 2012?

  10. 10

    Debug issue for OpenGL while using Visual Studio 2012

  11. 11

    Can you use SignalR with Visual Studio 2012?

  12. 12

    Can not install visual studio ultimate 2012

  13. 13

    visual studio 2012 debugger doesn't work

  14. 14

    Project doesn't open on Visual Studio 2012

  15. 15

    Visual Studio: Won't draw rectangle in a subwindow

  16. 16

    Why I can't see the debug output when I run a test in Visual Studio 2012?

  17. 17

    Can't see emulator selection option in visual studio 2012 for windows phone

  18. 18

    MTM With Visual Studio 2012 - Can't see Web Access with update 4

  19. 19

    Visual Studio 2012 new ASP Web Forms Application can't access textboxes from aspx file

  20. 20

    Why I can't see the debug output when I run a test in Visual Studio 2012?

  21. 21

    Can't seem to correctly add Helix Toolkit to my C# (Visual Studio Express 2012) project

  22. 22

    can't catch "ctor subscript out of range" exception in visual studio 2012

  23. 23

    Can't get OpenGL 3.3 draw a triangle, no errors thrown

  24. 24

    Can't draw a triangle with OpenGL ES 2.0 on android

  25. 25

    OpenGL: Can't draw vertices generated by a compute shader stored in SSBO

  26. 26

    Can't draw point in Android OpenGL ES 2.0

  27. 27

    Can't draw in OpenGL with pixel precision (not using fixed function pipeline)

  28. 28

    Can't draw point in Android OpenGL ES 2.0

  29. 29

    How can I switch themes in Visual Studio 2012

HotTag

Archive