Showing posts with label OpenGL. Show all posts
Showing posts with label OpenGL. Show all posts

4/28/2015

Error solver tip - >error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK, error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK

I meet the these error when I test example code in the CUDA by Example book.
--------------------------------------------------------------------------------------------------
main.cu.obj : error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8

1>main.cu.obj : error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4

1>M:\____MareResearch____\CUDA_application\testCuda1000\Debug\testCuda1000.exe : fatal error LNK1120: 2 unresolved externals
--------------------------------------------------------------------------------------------------

This errors are independent with cuda. It associated with the problem of OpenGL setting.

Firstly, let's check OpenGL related files.

: Window OS and VS 2012
*Header files
GL.h, GLU.h, glut.h (additionally, glext.h, wglext.h) are located in the below path.
" C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\GL "

*lib files
glut.lib, glut32.lib are located in 
" C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib "

*dll files
glut32.dll. glut.dll are located in 
"C:\Windows\System32"


*** ETC ***
: Visual Studio 2010
glut.h -> C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl
glut32.lib -> C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib
: Visual Studio 2008
glut.h -> C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl
glut32.lib -> C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
: Visual Studio 2005
glut.h -> C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\gl
glut32.lib -> C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib
: Visual Studio 6.0
glut.h -> C:\Program Files\Microsoft Visual Studio\VC98\Include\GL
glut32.lib -> C:\Program Files\Microsoft Visual Studio\VC98\Include\Lib


If you do not have OpenGL files, you can download from this site.
If you are testing example code of CUDA by example book and meet the same error like me, I modify one more thing.
I change the code in "gl_helper.h" like that..->

#include "GL/glut.h"
#include "GL/glext.h"
-->
#include < GL/glut.h>
#include < GL/glext.h>

Because "< " is referenced by VS path. Double quotes are referenced relative path and set by the user. 

If you installed the OpenGL well, it will be no errors to run the following sources:
..
#include < gl/glut.h>

void Display(){
 glClear(GL_COLOR_BUFFER_BIT);
 glBegin(GL_POLYGON);
 glVertex3f(-0.5,-0.5,0.0);
 glVertex3f(0.5,-0.5,0.0);
 glVertex3f(0.5,0.5,0.0);
 glVertex3f(-0.5,0.5,0.0);
 glEnd();
 glFlush();
}

int main(){
 glutCreateWindow("OpenGL Hello World!");
 glutDisplayFunc(Display);
 glutMainLoop();
 return 0;    
}

..


8/28/2012

OpenGL 2 Views(windows) on MFC - Source code

It is a source code to make 2 views(windows) of openGL on MFC dialog.


Download this source code here.
This source code is applied by OpenGL Drawing test on MFC post on this site.

8/20/2012

source code - OpenGL Drawing on MFC dlg(using COpenGLControl class)

This  post introduces how to drawing opengl on the mfc dialog.
If we are using COpenGLControl class, this work is very easy and simple.

Fi rstly, get the COpenGLControl class in the web or on this.

1. In the ~Dlg.h, Add header file and member variable

#include "OpenGLControl.h"
~
COpenGLControl m_oglWindow;


2. Add below source code in the OnInitDialog() function.

CRect rect;
// Get size and position of the template textfield we created before in the dialog editor
GetDlgItem(IDC_PIC_OPENGL)->GetWindowRect(rect);
// Convert screen coordinates to client coordinates
ScreenToClient(rect);
// Create OpenGL Control window
m_oglWindow.oglCreate(rect, this);
// Setup the OpenGL Window's timer to render
m_oglWindow.m_unpTimer = m_oglWindow.SetTimer(1, 1, 0);


* You have to set picture box option as "Visible is False".


The source code is here.

2/15/2012

(TIP) To get Color Information of specific pixel coordinate in the OpenGL

The method is simple to to get Color Information of specific pixel coordinate in the OpenGL is simple.
glReadPixels function enables these task.
The example source code is as follows.

struct{ GLubyte red, green, blue; } pixelColor;
glReadPixels(int(i), int(j), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixelColor);

But the drawback is too slow and we can get exact color information after view rendering.
Thanks.


2/09/2012

To Save OpenGL ViewPort to Image File (glReadPixels, OpenGL->OpenCV)


You can save the Viewport of OpenGL to Image file using glReadPixels function.
And this code is example for saving image file using openCV.
Thank you.

void CaptureViewPort()
{
 
 GLubyte * bits; //RGB bits
 GLint viewport[4]; //current viewport
  
 //get current viewport
 glGetIntegerv(GL_VIEWPORT, viewport);

 int w = viewport[2];
 int h = viewport[3];
 
 bits = new GLubyte[w*3*h];

 //read pixel from frame buffer
 glFinish(); //finish all commands of OpenGL
 glPixelStorei(GL_PACK_ALIGNMENT,1); //or glPixelStorei(GL_PACK_ALIGNMENT,4);
 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
 glReadPixels(0, 0, w, h, GL_BGR_EXT, GL_UNSIGNED_BYTE, bits);

 IplImage * capImg = cvCreateImage( cvSize(w,h), IPL_DEPTH_8U, 3);
 for(int i=0; i < h; ++i)
 {
  for(int j=0; j < w; ++j)
  {
   capImg->imageData[i*capImg->widthStep + j*3+0] = (unsigned char)(bits[(h-i-1)*3*w + j*3+0]);
   capImg->imageData[i*capImg->widthStep + j*3+1] = (unsigned char)(bits[(h-i-1)*3*w + j*3+1]);
   capImg->imageData[i*capImg->widthStep + j*3+2] = (unsigned char)(bits[(h-i-1)*3*w + j*3+2]);
  }
 }

 cvSaveImage("result.jpg",capImg); 
 cvReleaseImage(&capImg); 
 delete[] bits; 
 
}

1/10/2012

Sample source to make SubWindow in the OpenGL/ glutCreateSubWindow / Multi Window

This sample source is the method to make subwindow in the openGL programming.


The source may apply to your problem, because I have tried to make easy.
(Source Download)

#include "glut.h"
#include 
#include 

using namespace std;


#define GAP  25             /* gap between subwindows */
GLuint window, View1, View2, View3, View4;
GLuint sub_width = 256, sub_height = 256;

void main_display(void);
void main_reshape(int width,  int height);
void setfont(char* name, int size);
void drawstr(GLuint x, GLuint y, const char* format, int length);
GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_10;

void View1Display();
void View2Display();
void View3Display();
void View4Display();

void ResetViewport();

int main()
{
    //Mode Setting
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    //window size (+gap size)
    glutInitWindowSize(512+GAP*3, 512+GAP*3);
    //Initial position
    glutInitWindowPosition(50, 50);    

    //Main Window 
    window = glutCreateWindow("ViewPort Test");
    //Main Window callback function
    glutReshapeFunc(main_reshape);
    glutDisplayFunc(main_display);
    
    //World Window and Display
    View1 = glutCreateSubWindow(window, GAP, GAP, 256, 256);    
    glutDisplayFunc(View1Display);

    //screen Window and Display
    View2 = glutCreateSubWindow(window, GAP+256+GAP, GAP, 256, 256);
    glutDisplayFunc(View2Display);

    //command Window and Display
    View3 = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutDisplayFunc(View3Display);

    View4 = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutDisplayFunc(View4Display);


    glutMainLoop();

    return 0;
}

void main_display(void)
{
    //Background Color
    glClearColor(0.8, 0.8, 0.8, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //font color and style
    glColor3ub(0, 0, 0);
    setfont("helvetica", 12);

    //1st window name
    string str = "View1";
    drawstr(GAP, GAP-5, str.c_str(), str.length());

    //2st window name
    str = "View2";
    drawstr(GAP+sub_width+GAP, GAP-5, str.c_str(), str.length());

    //3st widnow name
    str = "View3";
    drawstr(GAP, GAP+sub_height+GAP-5, str.c_str(), str.length());

    //4st widnow name
    str = "View4";
    drawstr(GAP+sub_width+GAP, GAP+sub_height+GAP-5, str.c_str(), str.length());

    //last
    glutSwapBuffers();
}


//Background Window Setting
void main_reshape(int width,  int height) 
{
    //main view setting
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, width, height, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    sub_width = (width-GAP*3)/2.0;
    sub_height = (height-GAP*3)/2.0;

    //View1 Display
    glutSetWindow(View1);
    glutPositionWindow(GAP, GAP);
    glutReshapeWindow(sub_width, sub_height);

    //View2 Display
    glutSetWindow(View2);
    glutPositionWindow(GAP+sub_width+GAP, GAP);
    glutReshapeWindow(sub_width, sub_height);

    //View3 Display
    glutSetWindow(View3);
    glutPositionWindow(GAP, GAP+sub_height+GAP);
    glutReshapeWindow(sub_width, sub_height);


    //View4 Display
    glutSetWindow(View4);
    glutPositionWindow(GAP+sub_width+GAP, GAP+sub_height+GAP);
    glutReshapeWindow(sub_width, sub_height);
    //glutReshapeWindow(sub_width+GAP+sub_width, sub_height);    
}

//Font setting
void setfont(char* name, int size)
{
    font_style = GLUT_BITMAP_HELVETICA_10;
    if (strcmp(name, "helvetica") == 0) {
        if (size == 12) 
            font_style = GLUT_BITMAP_HELVETICA_12;
        else if (size == 18)
            font_style = GLUT_BITMAP_HELVETICA_18;
    } else if (strcmp(name, "times roman") == 0) {
        font_style = GLUT_BITMAP_TIMES_ROMAN_10;
        if (size == 24)
            font_style = GLUT_BITMAP_TIMES_ROMAN_24;
    } else if (strcmp(name, "8x13") == 0) {
        font_style = GLUT_BITMAP_8_BY_13;
    } else if (strcmp(name, "9x15") == 0) {
        font_style = GLUT_BITMAP_9_BY_15;
    }
}

//String Draw
void drawstr(GLuint x, GLuint y, const char* format, int length)
{
    glRasterPos2i(x, y);    
    for(int i=0; i        glutBitmapCharacter(font_style, *(format+i) );
}


//Display Teapot
void DrawScene()
{

    glColor3f(0.7, 0.7, 0.7);
    glPushMatrix();
    //glTranslatef(0.0, -1.0, 0.0);

    glBegin(GL_QUADS);
    glVertex3f(2.0, 0.0, 2.0);
    glVertex3f(2.0, 0.0, -2.0);
    glVertex3f(-2.0, 0.0, -2.0);
    glVertex3f(-2.0, 0.0, 2.0);
    glEnd();

    glPopMatrix();
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    glTranslatef(0.0, 0.0, -0.5);
    glutWireTeapot(1.0);
    glPopMatrix();

}

//View1Display
void View1Display(){

    
    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    DrawScene();
    glPopMatrix();
    glutSwapBuffers();
}

//View2Display
void View2Display(){

    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    gluLookAt(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    DrawScene();
    glPopMatrix();
    glutSwapBuffers();
}

//View3Display
void View3Display(){

    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    gluLookAt(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);
    DrawScene();
    glPopMatrix();
    glutSwapBuffers();
}


//View4Display
void View4Display(){

    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
        glLoadIdentity();
        gluPerspective(30, 1.0, 3.0, 50.0);
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
            gluLookAt(5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
            DrawScene();
        glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}


void ResetViewport()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.0, 2.0, -2.0, 2.0, 0.5, 5.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}


12/26/2011

How to install OpenGL in Window OS and Visula C++ 2008

You can download OpenCV 3.7 version on this web address http://www.opengl.org/resources/libraries/glut/glut37.zip
The Zip file has below files.



1) You have to copy these file into right directories.


x86  (32bit)
glut32.dll   = C:\Windows\System32
glut.dll       = C:\Windows\System32

x64 (62bit)
glut32.dll   = C:\Windows\sysWOW64
glut.dll       = C:\Windows\sysWOW64

glut.h        = C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl

glut.lib      = C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
glut32.lib = C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib

※  If you met some errors, Copy files additional folder.
C:\Program Files\Microsoft Visual Studio 9.0\VC\lib
C:\Program Files\Microsoft Visual Studio 9.0\VC\include
copy glut.lib, glut32.lib and glut.h into additional folders.

2) Visual Studio Setting
Linker->input, Additional Dependencies -> opengl32.lib glu32.lib glut32.lib

This is example source code.

#include 
void Draw()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0f, 0.0f, 1.0f);
    glBegin(GL_QUADS);
        glVertex3f(-0.5f, 0.5f, 0.5f);
        glVertex3f(0.5f, 0.5f, 0.5f);
        glVertex3f(0.5f, -0.5f, 0.5f);
        glVertex3f(-0.5f, -0.5f, 0.1f);
    glEnd();

    glFlush();
}

void main()
{
    glutCreateWindow("NeMo");
    glutDisplayFunc(Draw);
    glutMainLoop();
}

This setting process is normal course, but I met the this errors message in the Visual Studio 2008.
1>NeMo.obj : error LNK2001: __imp____glutCreateWindowWithExit@8 외부 기호를 확인할 수 없습니다.
1>C:\Users\mare\Documents\네이트온 받은 파일\NeMo\Debug\NeMo.exe : fatal error LNK1120: 1개의 확인할 수 없는 외부 참조입니다.

SO, I have solved this problem. I made OpenGL Folder at C:\OpenGL. The Folder has DLL, Lib, Header sub-folders. (DownLoad)
 

I have done directory setting in the Visual Studio options.
And you have to change #include <~> to #include "~" on the source code.

I want to suceess to complie OpneGL Project on your machine.
Thanks you.







8/29/2011

OpenGL Test - Lighting Position, Ambient, Diffuse, Specular, Shineness (Sphere, Cone, Tetrahedron, Teapot) - C++(MFC) Source / OpenGL을 이용한 광원의 위치와 주변광, 확산광, 반사광, 물체의 재질 테스트

Created Date : 2006.10
Language : C++(MFC)
Tool : Visual C++ 6.0
Library & Utilized : OpenGL
Reference :  OpenGL reference
etc. : -

This program is made for testing OpenGL properties.
The code test Light Position, Ambient, Diffuse, Specular and Surface Roughness.
I have made the program form view style interface.
We can adjust values by slide bar.
You can download entitle source code. < Here >


If you have good idea or advanced opinion, please reply me. Thank you
(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!)
Lighting Position Test

Ambient, Diffuse, Specular, Shininess Test

-------------------------------------------------------

OpenGL을 이용하여 광원의 위치와 주변광, 확산광, 반사광, 물체의 재질을 테스트 해 볼수 있는 프로그램입니다.
전체 소소는 여기서 받을 수 있습니다.


좋은 의견 어떤 글이든 답변 남겨주세요

감사합니다.

8/25/2011

Shape from Shading Matlab and C++(MFC) source

Created Date : 2007.8
Language : Matlab / C++(MFC)
Tool : Matlab / Visual C++ 6.0
Library & Utilized : - / OpenGL
Reference :  Shape from Shading, Photometric Stereo reference
etc. : -

Shading Source Images

Depth Image                            Normal Vector

Shading Source Images

Depth Image                            Normal Vector


Shading Source Images

Depth Image                            Normal Vector


This program make 3D shape using several different source of light.
The result is normal vector figure and 3D depth image.
This method is alternatively called as Photometric stereo.


You can download entire source code.
here -> https://github.com/MareArts/ShapeFromShading




If you have good idea or advanced opinion, please reply me. Thank you
(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!)



---------------------------------------------------------------------------

6개의 광원과 모델을 이용하여 3D 형상으로 복원하는 프로그램
3D 형상은 각 픽셀의 depth와 normal 방향을 계산하여 드로잉한다.
Photometric stereo 기법 이라고도 함.

여기서 전체 소스를 다운 받을 수 있습니다. <Matlab> < C++(MFC) >


좋은 의견 어떤 글이든 답변 남겨주세요

감사합니다.