Click here to Skip to main content
15,867,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to draw map boundary(red dash line) by reading (lat,log) from this file that i made from google earth that is space separated file.

45.521282 56.506097
46.061904 58.982127
46.477755 61.11857
46.563424 66.067484
46.510663 66.351164
46.489992 70.193384
46.295765 71.682091
46.276396 74.043388
46.227225 76.416976
45.862093 78.940809
45.593859 80.411673
44.607279 85.182343
43.197715 87.939209
41.272127 89.762752
40.317727 91.792808
39.135441 91.663431
36.670475 91.906478
34.944342 91.808325
34.017509 92.130071
32.644511 92.009376
31.36299 91.783157
28.325122 92.645321
28.051045 92.535264
25.457318 92.36974
22.890968 90.614442
22.83433 88.233479
22.342165 85.424715
22.776728 81.373231
22.006604 77.972075
22.010218 75.109263
22.479532 71.977007
23.692048 68.478777
24.748809 65.330189
25.090663 63.921219
25.665829 62.339933
26.020832 60.776496
27.148259 58.964778
29.678896 56.504676
31.878088 54.627588
34.282046 53.754322
38.088186 54.083552
41.498822 53.484212
44.544402 53.125854
45.394006 54.182066


On executing code in second section i am getting this error

C++
build/Debug/GNU-Linux/newForm.o: In function `Map::DrawMap(int, int, int, int)':
   newForm.cpp:71: undefined reference to `glLineWidth'
   newForm.cpp:73: undefined reference to `glBegin'
   newForm.cpp:78: undefined reference to `glVertex2f'
   newForm.cpp:80: undefined reference to `glEnd'
   build/Debug/GNU-Linux/newForm.o: In function `Map::Draw_Main_Map()':
   newForm.cpp:117: undefined reference to `glColor3f'
   newForm.cpp:118: undefined reference to `glLineWidth'
   newForm.cpp:120: undefined reference to `glEnable'
   newForm.cpp:121: undefined reference to `glBlendFunc'
   newForm.cpp:130: undefined reference to `glColor3f'
   newForm.cpp:131: undefined reference to `glColor3f'
   newForm.cpp:137: undefined reference to `glDisable'
   collect2: ld returned 1 exit status
   gmake[2]: *** [dist/Debug/GNU-Linux/Map] Error 1
   gmake[2]: Leaving directory `Map'
   gmake[1]: *** [.build-conf] Error 2
   gmake[1]: Leaving directory `Map'
   gmake: *** [.build-impl] Error 2
   
   BUILD FAILED (exit value 2, total time: 2s)


Here is Makefile in netbeans 8.1 for this project

# Environment 
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin


# build
build: .build-post

.build-pre:
# Add your pre 'build' code here...

.build-post: .build-impl
# Add your post 'build' code here...


# clean
clean: .clean-post

.clean-pre:
# Add your pre 'clean' code here...

.clean-post: .clean-impl
# Add your post 'clean' code here...


# clobber
clobber: .clobber-post

.clobber-pre:
# Add your pre 'clobber' code here...

.clobber-post: .clobber-impl
# Add your post 'clobber' code here...


# all
all: .all-post

.all-pre:
# Add your pre 'all' code here...

.all-post: .all-impl
# Add your post 'all' code here...


# build tests
build-tests: .build-tests-post

.build-tests-pre:
# Add your pre 'build-tests' code here...

.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...


# run tests
test: .test-post

.test-pre: build-tests
# Add your pre 'test' code here...

.test-post: .test-impl
# Add your post 'test' code here...


# help
help: .help-post

.help-pre:
# Add your pre 'help' code here...

.help-post: .help-impl
# Add your post 'help' code here...



# include project implementation makefile
include nbproject/Makefile-impl.mk

# include project make variables
include nbproject/Makefile-variables.mk


I am using netbean with C++ qt deigner made Qt form

What I have tried:

How i can make 2d map boundary in opengl using C++ 98.

How i can make this map resposive so that it get evirment and set display resolution according to it?

Here is my code that i made in QT with C++

Here is newForm.h

C++
#ifndef _NEWFORM_H
#define _NEWFORM_H

#include "ui_newForm.h"
#include <QtGui/qwidget.h>
#include <QtGui/QApplication>
#include <QtGui>
#include <qtooltip.h>
#include <QToolTip>
#include <qmessagebox.h>

#include "gl.h"
#include <GL/gl.h>
#include <GL/glu.h>


QT_BEGIN_NAMESPACE
namespace Ui
{
class newForm;
}
QT_END_NAMESPACE


class Map {
    
public:   
   
    void Draw_Main_Map();
    void DrawMap(int x, int y, int width, int height);
    void getLtLgsetNM(double x, double y, double mLat1, double mLon1, double &mLat, double &mLon);
    void getShowXYFromLatLong(double Lat, double Lon, double &x, double &y);
    void getXYFromLatLong(double mLat, double mLon, double &x, double &y);
    
    Map();
    ~Map();
};

class newForm : public QDialog {
    Q_OBJECT
public:    
    Map abc; 
    
    newForm();
    virtual ~newForm();
    
private:
    Ui::newForm widget;   
};


#endif /* _NEWFORM_H */


Here is newFrom.cpp


C++
#include "newForm.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <QWidget>
#include <GL/gl.h> 
#include <GL/gl.h>
#include <GL/gl.h>
#include <gl.h>
#include "gl.h"
#include "GL/gl.h"
#include <stdlib.h> 
#include <GL/gl.h>
#include <stdio.h>
#include "gl.h"
#include <GL/gl.h>
#include <GL/glu.h>



static const float RadFac = 57.29577951f;
static const float EarthRadius   = 3437.74677f;  
int GRange = 100;
int RadiusRange=0;
double displayX, displayY, displayX1, displayY1;
double RadiusLt, RadiusLn;
double ActRadius;
double c_lat = 0;
double c_long = 0;
int re_rng = 0;

float Pi = 3.142857143;
double GRefLat,GRefLong;
static double lt0 = GRefLat * (Pi/180);
static double ln0 = GRefLong * (Pi/180); 
double LamX;
double LamY;
double PLamX,PLamY;
static double n,p,fa;

static double  p0;

Map::Map() {

}

Map::~Map() {
    
}

newForm::newForm() {
    widget.setupUi(this);

}

newForm::~newForm() {
    
}


void  Map::DrawMap(int x, int y, int width, int height) {
    float PI = 3.142;
    const float DEGRAD = PI / 180;
    glLineWidth(3);

    glBegin(GL_LINE_LOOP);
    for (int angle = 0; angle <= 360; angle += 5) {
        float degRad = angle*DEGRAD;
        float x1 = ((width / 2 * cos(degRad)) + x);
        float y1 = ((height / 2 * sin(degRad)) + y);
        glVertex2f(x1, y1);
    }
    glEnd();
}
void Map::getShowXYFromLatLong(double Lat, double Lon, double &x, double &y)
{
    getXYFromLatLong(Lat, Lon, x, y);
    x = x - LamX;
    y = LamY - y;
    x =  x * PLamX;
    y =  y * PLamY;
}
void Map::getXYFromLatLong(double Lt, double Ln, double &x, double &y)
{
    double val;
    Lt = Lt*(Pi/180);
    Ln = Ln*(Pi/180);
    double temp = tan((double)Pi/4.0 + (double)Lt/2.0 );
    val = pow(temp, n);
    p =  fa /val;
         
    x = p * sin(n*(Ln - ln0))  ;
    y = p0 - p * cos(n*(Ln - ln0)) ;      
}
void Map::getLtLgsetNM(double x, double y, double Lt1, double Ln1, double &Lt, double &Ln){
    Lt = (y / 60) + Lt1;
    double Temp = (RadFac * acos((cos(sqrt(x*x+y*y)/ EarthRadius) - ( sin( Lt1 / RadFac ) * sin( Lt / RadFac ) )) / ( cos( Lt1 / RadFac ) * cos( Lt / RadFac )))) ;
    if (x>=0)
        Ln = Ln1 + Temp;
    else
        Ln = Ln1 - Temp;
}
void Map::Draw_Main_Map() {
    getLtLgsetNM(GRange, 0, c_lat, c_long, RadiusLt, RadiusLn);
    getShowXYFromLatLong(c_lat, c_long, displayX, displayY);
    getShowXYFromLatLong(RadiusLt, RadiusLn, displayX1, displayY1);

    ActRadius = ((displayX1 - displayX) * 2)  * 3.5 ;
    glColor3f(0.0, 0.0, 0.0);
    glLineWidth(3);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
    RadiusRange = re_rng;

    getLtLgsetNM(GRange, 0, c_lat, c_long, RadiusLt, RadiusLn);
    getShowXYFromLatLong(c_lat, c_long, displayX, displayY);
    getShowXYFromLatLong(RadiusLt, RadiusLn, displayX1, displayY1);

    ActRadius = ((displayX1 - displayX) * 2)  * 3.5; 

    glColor3f(0.0, 0.0, 0.15);
    glColor3f(0.0, 0.0, 0.7);
     
    DrawMap(displayX, displayY, ActRadius, ActRadius);  
   glDisable(GL_BLEND);
}



Here is Main.cpp file

C++
#include <QApplication>
#include "newForm.h"
#include <GL/gl.h> 
#include <GL/gl.h>
#include <GL/gl.h>
#include <QMainWindow>


int main(int argc, char *argv[]) {
 
    QApplication app(argc, argv);
    newForm *a = new newForm();
     a->abc.Draw_Main_Map();
    a->show();

 
    return app.exec();
}
Posted
Comments
Richard MacCutchan 18-Jun-22 4:33am    
You need to tidy up your includes; you have:
#include <GL/gl.h> 
#include <GL/gl.h>
#include <GL/gl.h>
#include <gl.h>
#include "gl.h"
#include "GL/gl.h"

And some of those repeated again in both the header and implementation files.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900