Using Windows 7 Home Premium 64bit with Visual Studio 2010 Professional on HP Pavilion g6. Code is written in C/C++.
在HP Pavilion g6上使用Windows 7 Home Premium 64位和Visual Studio 2010 Professional。代碼是用C / C ++編寫的。
Links:
Additional Include Directories: N/A - Everything needed is in the VS2010 Include Directory
Additional Library Directories: N/A - Everything needed is in the VS2010 Lib Directory
Additional Dependencies (Debug Mode): glew32d.lib;glew32sd.lib;glu32.lib;opengl32.lib;gdi32.lib;winmm.lib;user32.lib;
Code:
#include "stdafx.h"
#include <stdio.h>
#include <GL\glew.h>
#include <GL\wglew.h>
#include <GL\glut1.h>
#include <GL\glext.h>
using namespace std;
int main(int argc, char** argv)
{
glutInit(&argc, argv);
const unsigned char * version ;
version = (const unsigned char *)glGetString(GL_VERSION);
printf ("My OpenGL version is %s\n", version); //Comment this out for error in Glut, leave for the other 2 errors
// Obtain a buffer identifier from OpenGL
GLuint bufferID = 0;
glGenBuffers( 1, &bufferID ); //Comment out for no reported errors
return 0;
}
Reported Errors:
glut.h:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 486 - static void APIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
osfinfo.c:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 467 - return retval; // in function, int __cdecl __lock_fhandle (int fh)
dbgheap.c:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 504 - __finally {_munlock(_HEAP_LOCK);}
mlock.c:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 375 - } // end of function, void __cdecl _unlock (int locknum)
Other Noticed Symptoms:
其他注意到的症狀:
當printf命令未被注釋掉時,崩潰在osfinfo.c,dbgheap.c和mlock.c之間交替
當printf IS被注釋掉時,只會在glut.h上崩潰
當glGenBuffers被注釋掉時,沒有未處理的異常錯誤 - 程序不會崩潰
printf語句的輸出是:我的OpenGL版本是(null) - 無論程序是否崩潰都會發生
I'm completely stumped on this one, there appears to be literally nothing on the internet to help me out. I even focused on trying to solve the "OpenGL version = null" problem first, but I came out empty handed as I either followed the advice on this website incorrectly (not having a good enough understanding about OpenGL rendering contexts) or that problem is a symptom of the 0xC0000005 error.
我對這一點感到很難過,互聯網上幾乎沒有任何東西可以幫助我。我甚至專注於嘗試首先解決“OpenGL version = null”問題,但我空出來了,因為我要么錯誤地遵循了這個網站上的建議(對OpenGL渲染上下文沒有足夠的理解),或者問題是0xC0000005錯誤的症狀。
EDIT: As this problem seems to be caused by multiple problems I have decided to put an updated version of my code and the corresponding error I am getting from it. Thank you for helping me so far, but glGenBuffers just seems to hold a grudge on me or something.
編輯:由於這個問題似乎是由多個問題引起的,我決定把我的代碼的更新版本和我得到的相應錯誤。感謝你幫助我到目前為止,但glGenBuffers似乎只是對我或某事抱怨。
NEW Code:
#include "stdafx.h"
#include <cmath>
#include <math.h>
#include <iostream>
#include <GL\glew.h>
#include <GL\glut.h>
#include <GL\glext.h>
#include <GL\wglew.h>
#include <GL\wglext.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
using namespace std;
void drawScene();
void handleKeypress(unsigned char key, int x, int y);
void handleMouse(int button, int state, int x, int y);
void handleResize(int w, int h);
void update(int value);
void printw (float x, float y, float z, char* format, ...);
GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_24;
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(960, 460);
glutCreateWindow("Piece of Shit");
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutMouseFunc(handleMouse);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop();
return 0;
}
void drawScene()
{
double x, z;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
GLuint bufferID[1];
GLenum err = glewInit();
if (GLEW_OK != err)
printw(-6, 1.5, -10, "Fail: %s\n", glewGetErrorString(err));
printw(-3, 0.3, -10, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
glGenBuffers( 1, &bufferID[0] ); // comment out and you have no problems********************************
glutSwapBuffers();
}
void handleKeypress(unsigned char key, int x, int y)
{
}
void handleMouse(int button, int state, int x, int y)
{
}
void handleResize(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
void update(int value)
{
glutPostRedisplay();
glutTimerFunc(20, update, 0);
}
void printw (float x, float y, float z, char* format, ...)
{
va_list args; // Variable argument list
int len; // String length
int i; // Iterator
char* text; // Text
// Initialize a variable argument list
va_start(args, format);
// Return the number of characters in the string referenced the list of arguments.
// _vscprintf doesn't count terminating '\0' (that's why +1)
len = _vscprintf(format, args) + 1;
// Allocate memory for a string of the specified size
text = (char*) malloc (len * sizeof(char));
// Write formatted output using a pointer to the list of arguments
vsprintf_s(text, len, format, args);
// End using variable argument list
va_end(args);
// Specify the raster position for pixel operations.
glRasterPos3f (x, y, z);
// Draw the characters one by one
for (i = 0; text[i] != '\0'; i++)
glutBitmapCharacter(font_style, text[i]);
// Free the allocated memory for the string
free(text);
}
Error: gl_crap3.obj : error LNK2001: unresolved external symbol ___glewGenBuffers
錯誤:gl_crap3.obj:錯誤LNK2001:未解析的外部符號___glewGenBuffers
0
Your problem is probably that glGenBuffers isn't defined. I noticed that you're trying to use GLEW to solve that. You'll need to do a bit more to set up GLEW, as you guessed. You need a call to glewInit. My code looks something like (simplified for clarity):
你的問題可能是沒有定義glGenBuffers。我注意到你正試圖用GLEW解決這個問題。正如你猜測的那樣,你需要做更多的事情來設置GLEW。你需要調用glewInit。我的代碼看起來像(簡化為了清晰):
GLenum err = glewInit();
if (err != GLEW_OK) {
string error = "GLEW extension loading failed: "+string((char*)glewGetErrorString(err));
printf("%s\n",error); getchar();
}
Add that code after you set up a context (i.e., after glutInit). I don't know about your OpenGL version being NULL--the last time I encountered that was on a pretty old card--probably an integrated chipset. If that's your case, there's probably nothing to worry about.
在設置上下文后(即在glutInit之后)添加該代碼。我不知道你的OpenGL版本是NULL - 我最后一次遇到的是一張很舊的卡 - 可能是一個集成的芯片組。如果那是你的情況,那么可能沒有什么可擔心的。
0
Thank you for your help everybody. After playing around with this for over a week now I believe that the problem may be the Visual Studio 2010 Compiler itself 09/08/2012.
謝謝大家的幫助。在玩了一個多星期之后,我相信問題可能是Visual Studio 2010編譯器本身09/08/2012。
I will be trying Linux in an attempt to remedy my problem.
我將嘗試Linux以試圖解決我的問題。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/08/04/72096917868dd1c302b278abcb1dc28b.html。