プログラムは正常にビルドされます。
1>------ Rebuild All started: Project: 6E test, Configuration: Release Win32 ------
1> example1.cpp
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\Angel.h(65): warning C4305: 'initializing' : truncation from 'double' to 'const GLfloat'
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(698): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(699): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(700): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(721): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(723): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(726): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(742): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1> InitShader.cpp
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\Angel.h(65): warning C4305: 'initializing' : truncation from 'double' to 'const GLfloat'
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(698): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(699): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(700): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(721): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(723): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(726): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\niklas\downloads\6e_example1_vc10\6e test\code\mat.h(742): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>..\CODE\InitShader.cpp(10): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdio.h(218) : see declaration of 'fopen'
1> Generating code
1> Finished generating code
1> 6E test.vcxproj -> C:\Users\Niklas\Downloads\6E_example1_VC10\6E test\Release\6E test.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
しかし、実行時にクラッシュします。
C:\Users\Niklas\Downloads\6E_example1_VC10\6E test\Release\6E test.exe
OpenGL >2.1 context requested but wglCreateContextAttribsARB is not available
Falling back to legacy context creation
'6E test.exe' (Win32): Loaded 'C:\Users\Niklas\Downloads\6E_example1_VC10\6E test\Release\6E test.exe'. Symbols loaded.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Users\Niklas\Downloads\6E_example1_VC10\6E test\Release\glew32.dll'. Module was built without symbols.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110.dll'. Symbols loaded.
'6E test.exe' (Win32): Loaded 'C:\Users\Niklas\Downloads\6E_example1_VC10\6E test\Release\freeglut.dll'. Symbols loaded.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\opengl32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110.dll'. Symbols loaded.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dciman32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\PROGRA~2\McAfee\SITEAD~1\sahook.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'6E test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Cannot find or open the PDB file.
First-chance exception at 0x00000000 in 6E test.exe: 0xC0000005: Access violation executing location 0x00000000.
Unhandled exception at 0x7747BDA1 in 6E test.exe: 0xC0000005: Access violation executing location 0x00000000.
The program '[7868] 6E test.exe' has exited with code 0 (0x0).
Unhandled exception at 0x7747BDA1 in 6E test.exe: 0xC0000005: Access violation executing location 0x00000000.
何ができるでしょうか?デバッグを手伝ってもらえますか? このプログラムは、私が Visual Studio 2012 でビルドした OpenGL C プログラムの例です。
// Two-Dimensional Sierpinski Gasket
// Generated using randomly selected vertices and bisection
#include "Angel.h"
const int NumPoints = 5000;
//----------------------------------------------------------------------------
void
init( void )
{
vec2 points[NumPoints];
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 )
};
// Select an arbitrary initial point inside of the triangle
points[0] = vec2( 0.25, 0.50 );
// compute and store N-1 new points
for ( int i = 1; i < NumPoints; ++i ) {
int j = rand() % 3; // pick a vertex at random
// Compute the point halfway between the selected vertex
// and the previous point
points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
}
// Create a vertex array object
GLuint vao;
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader21.glsl", "fshader21.glsl" );
glUseProgram( program );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
//----------------------------------------------------------------------------
void
display( void )
{
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_POINTS, 0, NumPoints ); // draw the points
glFlush();
}
//----------------------------------------------------------------------------
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
//----------------------------------------------------------------------------
int
main( int argc, char **argv )
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutInitContextVersion( 3, 1 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutCreateWindow( "Sierpinski Gasket" );
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}
デバッグする方法は?
アップデート
プログラムをクラッシュさせるのは行glutCreateWindow
です。このようにコメントアウトすると、スタックトレースだけでなくウィンドウも表示されなくなります。
int
main( int argc, char **argv )
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutInitContextVersion( 3, 1 );
glutInitContextProfile( GLUT_CORE_PROFILE );
/*
glutCreateWindow( "Sierpinski Gasket" );
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutMainLoop();*/
return 0;
}
更新 2
以下は VS 2012 でビルドされますが、プログラムを実行しようとするとランタイム例外が発生します。私はそれがうまくいくと思うし、私はC ++を一緒にリンクする初心者です。
`// Two-Dimensional Sierpinski Gasket
// Generated using randomly selected vertices and bisection
#include "Angel.h"
const int NumPoints = 5000;
//----------------------------------------------------------------------------
void
init( void )
{
vec2 points[NumPoints];
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 )
};
// Select an arbitrary initial point inside of the triangle
points[0] = vec2( 0.25, 0.50 );
// compute and store N-1 new points
for ( int i = 1; i < NumPoints; ++i ) {
int j = rand() % 3; // pick a vertex at random
// Compute the point halfway between the selected vertex
// and the previous point
points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
}
// Create a vertex array object
GLuint vao;
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader21.glsl", "fshader21.glsl" );
glUseProgram( program );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
//----------------------------------------------------------------------------
void
display( void )
{
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_POINTS, 0, NumPoints ); // draw the points
glFlush();
}
//----------------------------------------------------------------------------
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
//----------------------------------------------------------------------------
int
main( int argc, char **argv )
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutInitContextVersion( 3, 1 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutInitWindowPosition( 0, 0 );
glutCreateWindow( "Sierpinski Gasket" );
glewInit();
init();
//glutDisplayFunc( display );
//glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}
Angel.h
ファイルは次のとおりです。
//////////////////////////////////////////////////////////////////////////////
//
// --- Angel.h ---
//
// The main header file for all examples from Angel 6th Edition
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __ANGEL_H__
#define __ANGEL_H__
//----------------------------------------------------------------------------
//
// --- Include system headers ---
//
#include <cmath>
#include <iostream>
// Define M_PI in the case it's not defined in the math header file
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
//----------------------------------------------------------------------------
//
// --- Include OpenGL header files and helpers ---
//
// The location of these files vary by operating system. We've included
// copies of open-soruce project headers in the "GL" directory local
// this this "include" directory.
//
#ifdef __APPLE__ // include Mac OS X verions of headers
# include <OpenGL/OpenGL.h>
# include <GLUT/glut.h>
#else // non-Mac OS X operating systems
# include <GL/glew.h>
// # include <GL/glut.h>
# include <GL/freeglut.h>
# include <GL/freeglut_ext.h>
#endif // __APPLE__
// Define a helpful macro for handling offsets into buffer objects
#define BUFFER_OFFSET( offset ) ((GLvoid*) (offset))
//----------------------------------------------------------------------------
//
// --- Include our class libraries and constants ---
//
namespace Angel {
// Helper function to load vertex and fragment shader files
GLuint InitShader( const char* vertexShaderFile,
const char* fragmentShaderFile );
// Defined constant for when numbers are too small to be used in the
// denominator of a division operation. This is only used if the
// DEBUG macro is defined.
const GLfloat DivideByZeroTolerance = GLfloat(1.0e-07);
// Degrees-to-radians constant
const GLfloat DegreesToRadians = M_PI / 180.0;
} // namespace Angel
#include "vec.h"
#include "mat.h"
#include "CheckError.h"
#define Print(x) do { std::cerr << #x " = " << (x) << std::endl; } while(0)
// Globally use our namespace in our example programs.
using namespace Angel;
#endif // __ANGEL_H__
アップデート 3
ここで提供された答えで私にとってはうまくいきますが、Angel.h
.
更新 4
でそれを行う方法を見つけましたAngel.h
。彼らの方法は、 to を再コード化してInitShader.cpp
からInitShader.h
、1 つの .cpp ファイルだけをインクルードすることです。
/* sierpinski gasket using vertex buffer objects */
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <vector>
#include <iostream>
#include "InitShader.h"
//////////////////////////////////////////////////////////////////////////////
//
// --- Angel.h ---
//
// The main header file for all examples from Angel 6th Edition
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __ANGEL_H__
#define __ANGEL_H__
//----------------------------------------------------------------------------
//
// --- Include system headers ---
//
#include <cmath>
#include <iostream>
// Define M_PI in the case it's not defined in the math header file
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
//----------------------------------------------------------------------------
//
// --- Include OpenGL header files and helpers ---
//
// The location of these files vary by operating system. We've included
// copies of open-soruce project headers in the "GL" directory local
// this this "include" directory.
//
#ifdef __APPLE__ // include Mac OS X verions of headers
# include <OpenGL/OpenGL.h>
# include <GLUT/glut.h>
#else // non-Mac OS X operating systems
# include <GL/glew.h>
// # include <GL/glut.h>
# include <GL/freeglut.h>
# include <GL/freeglut_ext.h>
#endif // __APPLE__
// Define a helpful macro for handling offsets into buffer objects
#define BUFFER_OFFSET( offset ) ((GLvoid*) (offset))
//----------------------------------------------------------------------------
//
// --- Include our class libraries and constants ---
//
namespace Angel {
// Helper function to load vertex and fragment shader files
//GLuint InitShader( const char* vertexShaderFile,
// const char* fragmentShaderFile );
// Defined constant for when numbers are too small to be used in the
// denominator of a division operation. This is only used if the
// DEBUG macro is defined.
const GLfloat DivideByZeroTolerance = GLfloat(1.0e-07);
// Degrees-to-radians constant
const GLfloat DegreesToRadians = M_PI / 180.0;
} // namespace Angel
#include "vec.h"
#include "mat.h"
#include "CheckError.h"
#define Print(x) do { std::cerr << #x " = " << (x) << std::endl; } while(0)
// Globally use our namespace in our example programs.
using namespace Angel;
#endif // __ANGEL_H__
const int NumPoints = 5000;
//----------------------------------------------------------------------------
void
init( void )
{
vec2 points[NumPoints];
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 )
};
// Select an arbitrary initial point inside of the triangle
points[0] = vec2( 0.25, 0.50 );
// compute and store N-1 new points
for ( int i = 1; i < NumPoints; ++i ) {
int j = rand() % 3; // pick a vertex at random
// Compute the point halfway between the selected vertex
// and the previous point
points[i] = ( points[i - 1] + vertices[j] ) * 0.5;
}
// Create a vertex array object
GLuint vao;
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader21.glsl", "fshader21.glsl" );
glUseProgram( program );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
//----------------------------------------------------------------------------
void
display( void )
{
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_POINTS, 0, NumPoints ); // draw the points
glFlush();
}
//----------------------------------------------------------------------------
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
//----------------------------------------------------------------------------
int
main( int argc, char **argv )
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutInitContextVersion( 3, 1 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutCreateWindow( "Sierpinski Gasket" );
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}